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);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

exratione’s picture

Attaching a patch to remove the DrupalPHPMailer::CreateHeader() override and go back to setting $this->Sender rather than $this->ReturnPath. That seemed like a better option than trying to divine the ultimate intent of DrupalPHPMailer::CreateHeader() and fix it, given that it doesn't achieve its stated purpose - it just loses the Return-Path rather than better managing it for more flexibility.

oadaeh’s picture

Issue summary: View changes

I've marked #2311623: Return-path not set as a duplicate of this.

fox_01’s picture

That attached patch #1 won't fix the problem with the bounce that sets the return patch described in #2311623: Return-path not set. I don't exactly know the api but bounce sets the return patch with standard hook_mail_alter. That should be respected by phpmailer

Also sender and return patch should possible to be set as different mail addresses. Its more common to have a returnpatch like bounce@domain.com and a sender like info@domain.com