php phpmailer:仅使用“回复”地址回复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10396264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phpmailer: Reply using only "Reply To" address
提问by chapmanio
I'm using phpmailer on my website and to help with spam issues I have created a mailbox to send these emails from (using SMTP).
我在我的网站上使用 phpmailer 并帮助解决垃圾邮件问题,我创建了一个邮箱来发送这些电子邮件(使用 SMTP)。
I have set the emails to come fromthe mailbox address and then I have added a reply toaddress for where I want the replies to go to:
我已经设置了电子邮件来从该邮箱地址,然后我添加了一个答辩的,我想答复转到地址:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tsl';
$mail->SMTPDebug = 1;
$mail->Host = EMAIL_HOST;
$mail->Port = EMAIL_PORT;
$mail->Username = EMAIL_USER;
$mail->Password = EMAIL_PASS;
$mail->SetFrom('[email protected]', 'Mailbox name');
$mail->AddReplyTo('[email protected]', 'Reply to name');
$mail->AddAddress('[email protected]', 'User name);
The emails send successfully and seem to get through the spam filters ok, but when I press reply it includes both the mailbox account and the reply to account.
电子邮件发送成功,似乎可以通过垃圾邮件过滤器,但是当我按下回复时,它同时包含邮箱帐户和对帐户的回复。
Is this what is meant to happen? I only want the reply to address to appear when you press reply. Is this even possible?
这是注定要发生的事情吗?我只希望在您按下回复时显示对地址的回复。这甚至可能吗?
Many thanks in advance for any help offered!
非常感谢您提供的任何帮助!
Edit:
编辑:
Looking at the email headers it seems like the from address is getting included in the reply to field. I have no idea why!
查看电子邮件标题,似乎发件人地址已包含在回复字段中。我不知道为什么!
Date: Tue, 1 May 2012 11:16:25 +0100
To: User name <[email protected]>
From: Mailbox name <[email protected]>
Reply-to: Mailbox name <[email protected]>, Reply to name <[email protected]
Subject: Email subject
Message-ID: <54c530c0d1f3ff33fc87c4c41c2c9ffd@localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_54c530c0d1f3ff33fc87c4c41c2c9ffd"
--b1_54c530c0d1f3ff33fc87c4c41c2c9ffd
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit
回答by chapmanio
I have found the answer to this, and it is annoyingly/frustratingly simple! Basically the reply to addresses needed to be added beforethe from address as such:
我已经找到了答案,这很烦人/令人沮丧地简单!基本上需要在发件人地址之前添加对地址的回复:
$mail->addReplyTo('[email protected]', 'Reply to name');
$mail->SetFrom('[email protected]', 'Mailbox name');
Looking at the phpmailer code in more detail this is the offending line:
更详细地查看 phpmailer 代码,这是违规行:
public function SetFrom($address, $name = '',$auto=1) {
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
if (!self::ValidateAddress($address)) {
$this->SetError($this->Lang('invalid_address').': '. $address);
if ($this->exceptions) {
throw new phpmailerException($this->Lang('invalid_address').': '.$address);
}
echo $this->Lang('invalid_address').': '.$address;
return false;
}
$this->From = $address;
$this->FromName = $name;
if ($auto) {
if (empty($this->ReplyTo)) {
$this->AddAnAddress('ReplyTo', $address, $name);
}
if (empty($this->Sender)) {
$this->Sender = $address;
}
}
return true;
}
Specifically this line:
特别是这一行:
if (empty($this->ReplyTo)) {
$this->AddAnAddress('ReplyTo', $address, $name);
}
Thanks for your help everyone!
谢谢大家的帮助!
回答by Fabian Peter
At least in the current versions of PHPMailers, there's a function clearReplyTos()to empty the reply-to array.
至少在当前版本的 PHPMailers 中,有一个函数clearReplyTos()来清空回复数组。
$mail->ClearReplyTos();
$mail->addReplyTo([email protected], 'EXAMPLE');

