• Probably since the latest version of included php-mailer library I got some issue with return path header on emails. I’m used to add a return-path header to get back the bounces on specific mailboxes.

    The return-path header is overwritten by many mail server if not passed, on unix, with -f command line parameter.

    Php-mailer does it only if the Sender variable is set, it does not check if there is a return-path header. So, plugins that add such header are not granted that it will be respected.

    To solve this “issue”, wp_mail can check the headers (as already done to extract from and fromname), look for a return-path header and use it’s value to set the phpmailer Sender value.

    Otherwise plugin should add a filter on phpmailer which is a lot more complex.

    Patch to pluggable.php file is (for version 3.3.1):

    switch ( strtolower( $name ) ) {
      case 'return-path':
      $return_path = trim($content);
      break;
    case 'from':
    if ( strpos($content, '<' ) !== false ) {
    
    @@ -308,6 +311,10 @@
    if ( !isset( $from_name ) )
      $from_name = 'WordPress';
    
    if (!empty($return_path)) {
      $phpmailer->Sender = $return_path;
    }

    what do you think? I tested it on a couple of servers with exim and postfix… some shared hosting have not that problem since they extract and “respect” the return path.

    Bye, Stefano.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I know it’s been months since you posted this but thanks for researching this matter and writing about it. With the help of your post I have created a tiny plugin that sets the return-path header to equal the from address. You can download it from my site:

    http://abdussamad.com/archives/567-Fixing-the-WordPress-Email-Return-Path-Header.html

    A much simpler solution in a plugin before wp_mail():

    global $phpmailer;
    $phpmailer->Sender = $return_path;

    Thread Starter Stefano Lissa

    (@satollo)

    As far as I know, phpmailer is not granted to be defined bofore the wp_mail() call, so if can lead to problems.

    The correct way is to atach a filter to the phpmailer hook and change the phpmailer values. My observations are out of date :-).

    Stefano.

    You’re right. The $phpmailer object doesn’t persist, but an instance is created with the first e-mail in each new sequence of e-mails. That means that $Sender cannot be altered before an instance of $phpmailer is created, only afterwards, correctly setting the Return-Path for the second and all subsequent e-mails in that sequence. A single e-mail cannot be sent out by itself with the correct Return-Path using this command. If you can advise me on the correct way to attach a filter to the phpmailer hook so that the value is set BEFORE the first e-mail is set, it might solve some problems.

    Thread Starter Stefano Lissa

    (@satollo)

    Hi, see my Mailer plugin, it uses the hook to filter the PHP mailer and set the Sender.

    Stefano.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Return Path management on wp_mail function’ is closed to new replies.