Update wp_mail to correctly call the Address adding functions on PHPMailer for To, CC, BCC in a way which preserves our support for full RFC2822 address specifications.

Older versions of PHPMailer were not too careful about validating what we passed in to them as a plain email address - the new version expects we pass in the Name and Email address seperately.
Fixes #17305 based on a patch from dllh.

git-svn-id: http://svn.automattic.com/wordpress/trunk@18006 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2011-05-23 11:14:05 +00:00
parent 30f64bdbb5
commit 5e908c7190
1 changed files with 29 additions and 3 deletions

View File

@ -296,6 +296,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
$tempheaders = $headers;
}
$headers = array();
$cc = array();
$bcc = array();
// If it's actually got contents
if ( !empty( $tempheaders ) ) {
@ -401,7 +403,15 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
foreach ( (array) $to as $recipient ) {
try {
$phpmailer->AddAddress( trim( $recipient ) );
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
$recipient_name = '';
if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
if ( count( $matches ) == 3 ) {
$recipient_name = $matches[1];
$recipient = $matches[2];
}
}
$phpmailer->AddAddress( trim( $recipient ), $recipient_name);
} catch ( phpmailerException $e ) {
continue;
}
@ -415,7 +425,15 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
if ( !empty( $cc ) ) {
foreach ( (array) $cc as $recipient ) {
try {
$phpmailer->AddCc( trim($recipient) );
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
$recipient_name = '';
if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
if ( count( $matches ) == 3 ) {
$recipient_name = $matches[1];
$recipient = $matches[2];
}
}
$phpmailer->AddCc( trim($recipient), $recipient_name );
} catch ( phpmailerException $e ) {
continue;
}
@ -425,7 +443,15 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
if ( !empty( $bcc ) ) {
foreach ( (array) $bcc as $recipient) {
try {
$phpmailer->AddBcc( trim($recipient) );
// Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
$recipient_name = '';
if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
if ( count( $matches ) == 3 ) {
$recipient_name = $matches[1];
$recipient = $matches[2];
}
}
$phpmailer->AddBcc( trim($recipient), $recipient_name );
} catch ( phpmailerException $e ) {
continue;
}