phpmailer:仅使用“回复”地址回复

时间:2012-05-01 10:11:26

标签: php 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);

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

这是什么意思发生的?我只想按回复时出现回复地址。这甚至可能吗?

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


修改

查看电子邮件标题,似乎来自地址的内容已包含在回复字段中。我不明白为什么!

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

2 个答案:

答案 0 :(得分:128)

我找到了答案,这令人烦恼/令人沮丧简单!基本上,地址的回复需要在之前添加来自地址:

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

感谢大家的帮助!

答案 1 :(得分:19)

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

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