PHP Mailer --- Reply-to: --- Return-path --- SetFrom

12,024

Solution 1

the correct way to set this (as of july 2013) is by using:

$mail->ReturnPath='[email protected]';

the phpmailer source contains the following, which is fairly self explanatory:

if ($this->ReturnPath) {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->ReturnPath).'>');
} elseif ($this->Sender == '') {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->From).'>');
} else {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->Sender).'>');
}

Solution 2

You may use

$mail->AddReplyTo('[email protected]', 'First Last');

Solution 3

$mail->AddReplyTo('[email protected]', 'Reply to email');
$mail->AddAddress('[email protected]', 'John Doe');

Notice the order! AddReplyTo has to be BEFORE AddAddress!!!

Share:
12,024

Related videos on Youtube

Papa De Beau
Author by

Papa De Beau

I am so grateful for the generous souls on here who help others with code. How amazing is that!

Updated on September 15, 2022

Comments

  • Papa De Beau
    Papa De Beau over 1 year

    I am sending mail via PHP Mailer. http://phpmailer.worxware.com/

    I want to be able to set the From to one emailand the REPLY-TO to another email and the RETURN-PATH to yet another.

    Mainly.. I want the bounced emails to go to something like [email protected] I was hoping the RETURN PATH could do this.

    And if a user who gets the email I don't want them to see its from BOUNCEDemails etc.. to I want to give them an option to reply to a real email address.

    I need the bounced emails tho to go to a seperate email because I don't want the REPLY TO to get many bad emails. etc..

    HERE IS WHAT I HAVE: Does Not work

    $mail->AddAddress('[email protected]', 'John Doe');
    $mail->AddReplyTo('[email protected]', 'Reply to email');
    $mail->SetFrom('[email protected]', 'From Name and Email');
    $mail->AddCustomHeader('Return-path: [email protected]');
    

    The code above replies to SetFrom and sends all bounces to SetFrom. Any ideas how to separate the two? Thanks