WordPress.org

Make WordPress Core

Changeset 39655


Ignore:
Timestamp:
12/30/2016 06:43:07 AM (17 months ago)
Author:
dd32
Message:

Mail: Ensure that any phpmailerException exceptions generated by setFrom() are caught to avoid PHP Fatal errors.

This change avoids a PHP fatal error that can be encountered when the specified (or generated) source email is an invalid address, such as wordpress@_, it makes no effort to set a valid source, only avoid the fatal error.

See #25239 for correcting the email address.
Fixes #39360.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r39639 r39655  
    186186    if ( isset( $atts['to'] ) ) {
    187187        $to = $atts['to'];
     188    }
     189
     190    if ( !is_array( $to ) ) {
     191        $to = explode( ',', $to );
    188192    }
    189193
     
    350354    $from_name = apply_filters( 'wp_mail_from_name', $from_name );
    351355
    352     $phpmailer->setFrom( $from_email, $from_name, false );
    353 
    354     // Set destination addresses
    355     if ( !is_array( $to ) )
    356         $to = explode( ',', $to );
     356    try {
     357        $phpmailer->setFrom( $from_email, $from_name, false );
     358    } catch ( phpmailerException $e ) {
     359        $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
     360        $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     361
     362        /** This filter is documented in wp-includes/pluggable.php */
     363        do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
     364
     365        return false;
     366    }
    357367
    358368    // Set mail's subject and body
     
    360370    $phpmailer->Body    = $message;
    361371
    362     // Use appropriate methods for handling addresses, rather than treating them as generic headers
     372    // Set destination addresses, using appropriate methods for handling addresses
    363373    $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
    364374
Note: See TracChangeset for help on using the changeset viewer.