Make WordPress Core

Ticket #39360: 39360.diff

File 39360.diff, 1.6 KB (added by dd32, 8 years ago)
  • src/wp-includes/pluggable.php

    function wp_mail( $to, $subject, $messag 
    337337         * @since 2.2.0
    338338         *
    339339         * @param string $from_email Email address to send from.
    340340         */
    341341        $from_email = apply_filters( 'wp_mail_from', $from_email );
    342342
    343343        /**
    344344         * Filters the name to associate with the "from" email address.
    345345         *
    346346         * @since 2.3.0
    347347         *
    348348         * @param string $from_name Name associated with the "from" email address.
    349349         */
    350350        $from_name = apply_filters( 'wp_mail_from_name', $from_name );
    351351
    352         $phpmailer->setFrom( $from_email, $from_name, false );
     352        try {
     353                $phpmailer->setFrom( $from_email, $from_name, false );
     354        } catch ( phpmailerException $e ) {
     355                $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
     356                $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     357
     358                /** This filter is documented in wp-includes/pluggable.php */
     359                do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
     360
     361                return false;
     362        }
    353363
    354364        // Set destination addresses
    355365        if ( !is_array( $to ) )
    356366                $to = explode( ',', $to );
    357367
    358368        // Set mail's subject and body
    359369        $phpmailer->Subject = $subject;
    360370        $phpmailer->Body    = $message;
    361371
    362372        // Use appropriate methods for handling addresses, rather than treating them as generic headers
    363373        $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
    364374
    365375        foreach ( $address_headers as $address_header => $addresses ) {
    366376                if ( empty( $addresses ) ) {
    367377                        continue;