[wp-trac] [WordPress Trac] #18792: Wrong FROM email when using wp_mail and built in mail() function

WordPress Trac noreply at wordpress.org
Tue Sep 17 09:35:11 UTC 2013


#18792: Wrong FROM email when using wp_mail and built in mail() function
-------------------------------------------------+-------------------------
 Reporter:  pigster                              |       Owner:  westi
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  Awaiting
Component:  External Libraries                   |  Review
 Severity:  major                                |     Version:  3.2.1
 Keywords:  has-patch needs-testing needs-unit-  |  Resolution:
  tests 2nd-opinion                              |
-------------------------------------------------+-------------------------
Changes (by gruvin):

 * keywords:  has-patch needs-refresh dev-feedback => has-patch needs-
     testing needs-unit-tests 2nd-opinion


Comment:

 OK. Here's a patch that takes care of all of the above.

 This patch makes the original changes suggested by ''pigster'' and
 implement an OP class friendly version of ''KevinHamilton's'' Sender=''
 fix, as noted above.

 I've tested the following patch within the context that I understand the
 original bug and it appears to work fine. My mail from Wordpress is now
 being sent from the correct server IP address for the domain being used
 and from the correct sender address. This results in correct SPF records
 being used and in the likes of Gmail not marking such messages as spam.

 {{{
 Index: class-phpmailer.php
 ===================================================================
 --- class-phpmailer.php (revision 25393)
 +++ class-phpmailer.php (working copy)
 @@ -2320,6 +2320,16 @@
    }

    /**
 +   * Clears from address and name. Also clears Sender.  Returns void.
 +   * @return void
 +   */
 +  public function ClearFrom() {
 +    $this->From='';
 +    $this->FromName='';
 +    $this->Sender='';
 +  }
 +
 +  /**
     * Clears all recipients assigned in the ReplyTo array.  Returns void.
     * @return void
     */
 Index: pluggable.php
 ===================================================================
 --- pluggable.php       (revision 25393)
 +++ pluggable.php       (working copy)
 @@ -313,6 +313,7 @@
         $phpmailer->ClearCCs();
         $phpmailer->ClearCustomHeaders();
         $phpmailer->ClearReplyTos();
 +        $phpmailer->ClearFrom();

         // From email and name
         // If we don't have a name from the input headers
 @@ -337,9 +338,9 @@
         }

         // Plugin authors can override the potentially troublesome default
 -       $phpmailer->From     = apply_filters( 'wp_mail_from'     ,
 $from_email );
 -       $phpmailer->FromName = apply_filters( 'wp_mail_from_name',
 $from_name  );

 +        $phpmailer->SetFrom(apply_filters( 'wp_mail_from'     ,
 $from_email ), apply_filters( 'wp_mail_from_name', $from_name  ));
 +
         // Set destination addresses
         if ( !is_array( $to ) )
                 $to = explode( ',', $to );
 }}}

--
Ticket URL: <http://core.trac.wordpress.org/ticket/18792#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list