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. git-svn-id: https://develop.svn.wordpress.org/trunk@39655 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f6fa5ddda7
commit
247e08e84a
@ -187,6 +187,10 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
|
|||||||
$to = $atts['to'];
|
$to = $atts['to'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !is_array( $to ) ) {
|
||||||
|
$to = explode( ',', $to );
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $atts['subject'] ) ) {
|
if ( isset( $atts['subject'] ) ) {
|
||||||
$subject = $atts['subject'];
|
$subject = $atts['subject'];
|
||||||
}
|
}
|
||||||
@ -349,17 +353,23 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
|
|||||||
*/
|
*/
|
||||||
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
|
||||||
|
|
||||||
|
try {
|
||||||
$phpmailer->setFrom( $from_email, $from_name, false );
|
$phpmailer->setFrom( $from_email, $from_name, false );
|
||||||
|
} catch ( phpmailerException $e ) {
|
||||||
|
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
|
||||||
|
$mail_error_data['phpmailer_exception_code'] = $e->getCode();
|
||||||
|
|
||||||
// Set destination addresses
|
/** This filter is documented in wp-includes/pluggable.php */
|
||||||
if ( !is_array( $to ) )
|
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
|
||||||
$to = explode( ',', $to );
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set mail's subject and body
|
// Set mail's subject and body
|
||||||
$phpmailer->Subject = $subject;
|
$phpmailer->Subject = $subject;
|
||||||
$phpmailer->Body = $message;
|
$phpmailer->Body = $message;
|
||||||
|
|
||||||
// Use appropriate methods for handling addresses, rather than treating them as generic headers
|
// Set destination addresses, using appropriate methods for handling addresses
|
||||||
$address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
|
$address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
|
||||||
|
|
||||||
foreach ( $address_headers as $address_header => $addresses ) {
|
foreach ( $address_headers as $address_header => $addresses ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user