Make WordPress Core

Changeset 18006


Ignore:
Timestamp:
05/23/2011 11:14:05 AM (13 years ago)
Author:
westi
Message:

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.

File:
1 edited

Legend:

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

    r17753 r18006  
    297297        }
    298298        $headers = array();
     299        $cc = array();
     300        $bcc = array();
    299301
    300302        // If it's actually got contents
     
    402404    foreach ( (array) $to as $recipient ) {
    403405        try {
    404             $phpmailer->AddAddress( trim( $recipient ) );
     406            // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
     407            $recipient_name = '';
     408            if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
     409                if ( count( $matches ) == 3 ) {
     410                    $recipient_name = $matches[1];
     411                    $recipient = $matches[2];
     412                }
     413            }
     414            $phpmailer->AddAddress( trim( $recipient ), $recipient_name);
    405415        } catch ( phpmailerException $e ) {
    406416            continue;
     
    416426        foreach ( (array) $cc as $recipient ) {
    417427            try {
    418                 $phpmailer->AddCc( trim($recipient) );
     428                // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
     429                $recipient_name = '';
     430                if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
     431                    if ( count( $matches ) == 3 ) {
     432                        $recipient_name = $matches[1];
     433                        $recipient = $matches[2];
     434                    }
     435                }
     436                $phpmailer->AddCc( trim($recipient), $recipient_name );
    419437            } catch ( phpmailerException $e ) {
    420438                continue;
     
    426444        foreach ( (array) $bcc as $recipient) {
    427445            try {
    428                 $phpmailer->AddBcc( trim($recipient) );
     446                // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
     447                $recipient_name = '';
     448                if( preg_match( '/(.+)\s?<(.+)>/', $recipient, $matches ) ) {
     449                    if ( count( $matches ) == 3 ) {
     450                        $recipient_name = $matches[1];
     451                        $recipient = $matches[2];
     452                    }
     453                }
     454                $phpmailer->AddBcc( trim($recipient), $recipient_name );
    429455            } catch ( phpmailerException $e ) {
    430456                continue;
Note: See TracChangeset for help on using the changeset viewer.