php - 在电子邮件中设置回复字段

标签 php email

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

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

有什么方法可以让 email1@example.com 从 TO 字段中删除,只显示在 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);

最佳答案

尝试:

$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 需要改变这种行为。它将发件人地址添加到回复字段。如果您在发件人地址之前先设置回复,它将无法将您的发件人地址添加到回复标题。

关于php - 在电子邮件中设置回复字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145168/

相关文章:

php - PHP 的逻辑运算符与 JavaScript 的一样吗?

php - 捕获包含 "."或 ":"但不以句点结尾的行

php - 如何使用@import 连接 CSS 文件?

php - 使用 laravel 5.4 向多个收件人发送邮件

python imaplib 意外响应 220

java - 如何检查邮件地址是否存在?

java - 通过电子邮件发送文件 - 无法获取附件 - Android

php - 几乎相同的代码,但输出不同,为什么?

php - 带有 MySQLi 的 PHP 中的多个准备好的语句

vba - 根据日期自动从 Excel 发送电子邮件