Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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);
Comment | File | Size | Author |
---|---|---|---|
#1 | phpmailer-enable-return-path-header-1505444.patch | 1.33 KB | exratione |
Comments
Comment #1
exratione CreditAttribution: exratione commentedAttaching 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.
Comment #2
oadaeh CreditAttribution: oadaeh commentedI've marked #2311623: Return-path not set as a duplicate of this.
Comment #3
fox_01 CreditAttribution: fox_01 commentedThat 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