Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting replyTo field in email

Tags:

php

email

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 '[email protected]' but I need replies to come to '[email protected]'

I have added [email protected] 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 [email protected] and [email protected] are being shown in the TO field.

Is there any way that I can have [email protected] 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 [email protected]
    $this->phpmailer->AddReplyTo($replyEmail,$fromName);  //this is [email protected]
    $this->phpmailer->Subject = $subject;
    $this->phpmailer->AltBody = $msgTXT; // non-html text
    $this->phpmailer->MsgHTML($msgHTML); // html body-text
    $this->phpmailer->AddAddress($email);
like image 675
Undefined Variable Avatar asked Feb 20 '23 09:02

Undefined Variable


1 Answers

Try:

$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->AddReplyTo($replyEmail,$fromName);  //this is [email protected]
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is [email protected]
$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.

like image 69
rationalboss Avatar answered Feb 22 '23 00:02

rationalboss