Make WordPress Core

Ticket #23291: 23291.4.diff

File 23291.4.diff, 5.0 KB (added by iandunn, 12 years ago)
  • wp-login.php

     
    263263        $title = apply_filters('retrieve_password_title', $title);
    264264        $message = apply_filters('retrieve_password_message', $message, $key);
    265265
    266         if ( $message && !wp_mail($user_email, $title, $message) )
    267                 wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
     266        if ( $message ) {
     267                $mail_status = wp_mail( $user_email, $title, $message, '', array(), true );
    268268
     269                // mailer_send indicates the messages wasn't sent. Other error codes indicate the message was sent even though errors occurred.
     270                if ( is_wp_error( $mail_status ) && in_array( 'mailer_send', $mail_status->get_error_codes() ) ) {
     271                        $mail_error_messages = implode( ". ", $mail_status->get_error_messages() );
     272                        wp_die( __( 'The e-mail could not be sent.' ) . "<br />\n" . sprintf( __( '<strong>ERROR</strong>: %s' ), $mail_error_messages ) );
     273                }
     274        } else {
     275                $errors->add( 'message_empty', __( '<strong>ERROR</strong>: Message was empty.' ) );
     276                return $errors;
     277        }
     278
    269279        return true;
    270280}
    271281
  • wp-includes/pluggable.php

     
    209209 * @param string $message Message contents
    210210 * @param string|array $headers Optional. Additional headers.
    211211 * @param string|array $attachments Optional. Files to attach.
    212  * @return bool Whether the email contents were sent successfully.
     212 * @param string $wp_error Optional. false to return boolean false on error, true to return a WP_Error object. Defaults to false.
     213 * @return bool|WP_Error Boolean true if the email was sent successfully. Boolean false or WP_Error if sending failed. WP_Error if email was sent, but with errors.
    213214 */
    214 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
     215function wp_mail( $to, $subject, $message, $headers = '', $attachments = array(), $wp_error = false ) {
     216        $errors = new WP_Error();
     217       
    215218        // Compact the input, apply the filters, and extract them back out
    216219        extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
    217220
     
    356359                        }
    357360                        $phpmailer->AddAddress( $recipient, $recipient_name);
    358361                } catch ( phpmailerException $e ) {
     362                        $errors->add( 'mailer_add_address', $e->getMessage() );
    359363                        continue;
    360364                }
    361365        }
     
    378382                                }
    379383                                $phpmailer->AddCc( $recipient, $recipient_name );
    380384                        } catch ( phpmailerException $e ) {
     385                                $errors->add( 'mailer_add_cc', $e->getMessage() );
    381386                                continue;
    382387                        }
    383388                }
     
    396401                                }
    397402                                $phpmailer->AddBcc( $recipient, $recipient_name );
    398403                        } catch ( phpmailerException $e ) {
     404                                $errors->add( 'mailer_add_bcc', $e->getMessage() );
    399405                                continue;
    400406                        }
    401407                }
     
    439445                        try {
    440446                                $phpmailer->AddAttachment($attachment);
    441447                        } catch ( phpmailerException $e ) {
     448                                $errors->add( 'mailer_add_attachment', $e->getMessage() );
    442449                                continue;
    443450                        }
    444451                }
     
    448455
    449456        // Send!
    450457        try {
    451                 return $phpmailer->Send();
     458                $mail_status = $phpmailer->Send();
     459
     460                if ( true == $wp_error && count( $errors->get_error_codes() ) > 0 ) {
     461                        return $errors;
     462                } else {
     463                        return $mail_status;
     464                }
    452465        } catch ( phpmailerException $e ) {
    453                 return false;
     466                $errors->add( 'mailer_send', $e->getMessage() );
     467
     468                if ( true == $wp_error ) {
     469                        return $errors;
     470                } else {
     471                        return false;
     472                }
    454473        }
    455474}
    456475endif;
     
    10731092        $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
    10741093        $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
    10751094
    1076         @wp_mail( $author->user_email, $subject, $notify_message, $message_headers );
     1095        wp_mail( $author->user_email, $subject, $notify_message, $message_headers );
    10771096
    10781097        return true;
    10791098}
     
    11561175        $message_headers = apply_filters('comment_moderation_headers', $message_headers);
    11571176
    11581177        foreach ( $email_to as $email )
    1159                 @wp_mail($email, $subject, $notify_message, $message_headers);
     1178                wp_mail( $email, $subject, $notify_message, $message_headers );
    11601179
    11611180        return true;
    11621181}
     
    12031222        $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    12041223        $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
    12051224
    1206         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
     1225        wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message );
    12071226
    12081227        if ( empty($plaintext_pass) )
    12091228                return;
  • wp-admin/includes/upgrade.php

     
    276276http://wordpress.org/
    277277"), $blog_url, $name, $password);
    278278
    279         @wp_mail($email, __('New WordPress Site'), $message);
     279        wp_mail( $email, __( 'New WordPress Site' ), $message );
    280280}
    281281endif;
    282282