If you set the Return-Path header in code it will be discarded in favor of the from address. Under a range of circumstances it is important to be able to set the Return-Path in code - for example when running a mailing list, or processing bounced email.

function my_module_mail_alter(&$message) {
   // Will be ignored.
   $message['headers']['Return-Path'] = 'return-path@example.com'
}

This is an example of what you have to do with PHPMailer in order to set a Return-Path header such that it is different from the Reply-To or From headers:

$mail->Sender = $return_path_email;
$mail->From = $from_email;
$mail->FromName = $from_name;
$mail->AddAddress($to_email);

Comments

exratione’s picture

StatusFileSize
new391 bytes

Patch attached.

simon georges’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Status: Active » Needs review

Changing status, as there is a patch.

wundo’s picture

Status: Needs review » Needs work

Could you please re-roll the patch?

simon georges’s picture

Status: Needs work » Needs review
StatusFileSize
new392 bytes

Patch re-rolled. Caution: no test done.

jonhattan’s picture

Status: Needs review » Reviewed & tested by the community

It works!

jonhattan’s picture

Issue summary: View changes

More info.

josesanmartin’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

This has been commited to dev. Thank you exratione and Simeon, have a happy new year! :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

nathaniel’s picture

Hello, I just want to note that this bit of code sets my Sender to blank if the Return-Path header is blank and causes email to fail. Had to comment it out for now. I think the empty Return-Path header is coming from the mimemail module.

<?php
case 'return-path':
  // $mailer->Sender = $value;
  break;
?>
Anders Kallin’s picture

I think that this fix is incompatible with this patch, no?
https://drupal.org/node/1686588#comment-7468620

And why set 'Sender' when we really want to set 'Return-Path'?
Oh,it's the phpmailer implementation that unfortunately uses them interchangeably.