Phpmailer: 只使用“回复”地址回复

我在我的网站上使用 phpmailer,并且为了帮助解决垃圾邮件问题,我创建了一个邮箱来发送这些邮件(使用 SMTP)。

我已经设置了电子邮件来 来自的邮箱地址,然后我已经添加了一个 答复的地址,我想要的答复去:

$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('mailbox@email.com', 'Mailbox name');
$mail->AddReplyTo('replyto@email.com', 'Reply to name');
$mail->AddAddress('user@email.com', 'User name);

电子邮件发送成功,似乎通过垃圾邮件过滤器 OK,但是当我按回复时,它包括邮箱帐户和回复帐户

这是命中注定的吗?我只希望在您按下回复时出现回复地址。这有可能吗?

非常感谢您提供的任何帮助!


编辑:

看看电子邮件标题,似乎从地址正在得到包括在回复字段。我不知道为什么!

Date: Tue, 1 May 2012 11:16:25 +0100
To: User name <user@email.com>
From: Mailbox name <mailbox@email.com>
Reply-to: Mailbox name <mailbox@email.com>, Reply to name <replyto@email.com
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
129681 次浏览

我已经找到了这个问题的答案,而且它简单得令人恼火/沮丧!基本上,对地址的答复需要加上 之前这样的来自地址:

$mail->addReplyTo('replyto@email.com', 'Reply to name');
$mail->SetFrom('mailbox@email.com', 'Mailbox name');

更详细地查看 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;
}

特别是这句话:

if (empty($this->ReplyTo)) {
$this->AddAnAddress('ReplyTo', $address, $name);
}

谢谢大家的帮助!

至少在当前版本的 PHPMailers 中,有一个函数 ClearReplyTos ()来清空回复数组。

    $mail->ClearReplyTos();
$mail->addReplyTo(example@example.com, 'EXAMPLE');