在电子邮件中设置replyTo字段

时间:2012-08-27 15:44:33

标签: php email

我有一个SMTP问题。我创建了一个PHP脚本来发送电子邮件。要求是我需要从'email1@example.com'发送电子邮件,但我需要回复'email2@example.com'

我在email2@example.com标头字段中添加了reply-to。我遇到的唯一问题是当有人收到电子邮件并点击回复按钮时,email1@example.comemail2@example.com都会显示在TO字段中。

我是否有任何方式可以从“收件人”字段中删除email1@example.com并仅显示reply-to字段中指定的电子邮件地址?

我使用的是PHPMailer,代码如下:

    $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);

2 个答案:

答案 0 :(得分:8)

尝试:

$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);

首先尝试在SetFrom之前设置AddReplyTo()。 phpmailer需要改变这种行为。它将from地址添加到reply-to字段。如果您在发件人地址之前设置了回复号码,则无法将您的收件人地址添加到回复标题中。

答案 1 :(得分:0)

From a google search and first result

  

添加回复地址^

     

默认情况下,回复地址将是FROM地址,除非您另行指定。这只是电子邮件客户端情报。但是,您可以将电子邮件来自一个电子邮件地址,并且任何回复都会转到另一个电子邮件地址。方法如下:

     

$mailer->AddReplyTo('billing@yourdomain.com', 'Billing Department');

     

注意:   您可以拥有多个回复地址,只需复制上一代码示例中的行并更改每行的电子邮件地址。

您需要在收件人地址前添加此行。 p lease check out this for the solution to the same problem.

按照这些示例,您的代码应该看起来像

$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->AltBody = $msgTXT; // non-html text
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);