4

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);
Undefined Variable
  • 4,196
  • 10
  • 40
  • 69

2 Answers2

9

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.

rationalboss
  • 5,330
  • 3
  • 30
  • 50
-1

From a google search and first result

Adding a Reply-To Address ^

By default the Reply-To address will be the FROM address unless you specify otherwise. That is simply E-Mail client intelligence. However, you can have the E-Mail come from one E-Mail address and any replies go to a different one. Here's how:

$mailer->AddReplyTo('[email protected]', 'Billing Department');

NOTE: You can have multiple Reply-To addresses, just duplicate the line in the previous code example and change the E-Mail address on each line.

You will need to add this line before your from address. Please check out this for the solution to the same problem.

Following these examples, your code should look like

$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->AltBody = $msgTXT; // non-html text
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);
Community
  • 1
  • 1
bretterer
  • 5,693
  • 5
  • 32
  • 53