[wp-trac] [WordPress Trac] #21659: wp_mail() problem with Reply-To header

WordPress Trac noreply at wordpress.org
Fri Jul 1 11:14:51 UTC 2016


#21659: wp_mail() problem with Reply-To header
--------------------------------------+-----------------------------
 Reporter:  pavelevap                 |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Future Release
Component:  Mail                      |     Version:  3.4.1
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------

Comment (by stephenharris):

 It looks good: it fixes the bug, passes the tests and removes some
 duplicate code. My only concern is that using variable variables is
 slightly cryptic and difficult to follow. Could `to`, `cc` , `bcc` and
 `reply_to` be keys in an array rather than variable names, avoiding the
 need for`$$address_header`?

 Additionally my personal preference would be to use an explicit `switch`
 statement rather than `$header_method_map` and `call_user_func` - it's
 slightly more lines, but it reads a little more easily:

 {{{#!php
  try {
         // Break $recipient into name and address parts if in the format
 "Foo <bar at baz.com>"
        $recipient_name = '';

        if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
               if ( count( $matches ) == 3 ) {
                      $recipient_name = $matches[1];
                      $address        = $matches[2];
               }
        }

        switch ( $address_header ) {
               case 'to':
                      $phpmailer->AddAddress( $address, $recipient_name );
                      break;
               case 'cc':
                      $phpmailer->AddCc( $address, $recipient_name );
                      break;
               case 'bcc':
                      $phpmailer->AddBcc( $address, $recipient_name );
                      break;
               case 'reply_to':
                      $phpmailer->AddReplyTo( $address, $recipient_name );
                      break;
        }
 } catch ( phpmailerException $e ) {
        continue;
 }
 }}}

 I'd agree that none of the changes in that patch are out-of-scope.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21659#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list