67

我在我的网站上使用 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);

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

这是要发生的事情吗?我只希望在您按下回复时出现对地址的回复。这甚至可能吗?

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


编辑:

查看电子邮件标题,发件人地址似乎包含在回复字段中。我不知道为什么!

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
4

2 回答 2

161

我已经找到了答案,这很烦人/令人沮丧的简单!基本上需要在发件人地址之前添加对地址的回复,如下所示:

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

谢谢大家的帮助!

于 2012-05-03T13:50:42.073 回答
38

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

    $mail->ClearReplyTos();
    $mail->addReplyTo(example@example.com, 'EXAMPLE');
于 2014-07-21T11:36:04.070 回答