I have an SMTP question. I have created a PHP script to send out emails. The requirement is that I need to send email from 'email1@example.com' but I need replies to come to 'email2@example.com'
I have added email2@example.com
in the reply-to
header field. The only problem I am having is that when someone receives the email and clicks on the reply button, both email1@example.com
and email2@example.com
are being shown in the TO
field.
Is there any way that I can have email1@example.com
removed from the TO field and only show the email address that was specified in the reply-to
field?
I am using PHPMailer and the code is below:
$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1@example.com
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2@example.com
$this->phpmailer->Subject = $subject;
$this->phpmailer->AltBody = $msgTXT; // non-html text
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);
Try:
$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2@example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1@example.com
$this->phpmailer->Subject = $subject;
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);
Try setting AddReplyTo() first before SetFrom. phpmailer needs to change this behavior. It adds the from address to the reply-to field. If you set reply-to first before the from address, it will not be able to add your from address to the reply-to header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With