在邮件头中使用List-Unsubscribe会导致邮件无法被发送到Gmail。

6
我正在使用phpmailer发送电子邮件。
当我添加list-unsubscribe时,电子邮件将被传递到所有帐户,除了gmail。它只是被丢弃了,不会进入垃圾邮件,也不会到达gmail帐户。当我删除list-unsubscribe时,电子邮件成功发送到gmail帐户。
这是我正在使用的list-unsubscribe:
List-Unsubscribe:<http://keepity.com>,<mailto:admin@keepity.com>

这是在phpmailer中的称呼:
$mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin@keepity.com>");

这是调用phpmailer的完整函数。如果我注释掉list-unsubscribe,那么邮件可以被送达到Gmail帐户,否则它从未到达。有人知道为什么会送不到吗?

static function phpmailer_sendmail($mail,$from,$fromAlias,$to,$replyTo,$replyToAlias,$subject,$html,$text) {

    require_once (JPATH_COMPONENT.DS.'PHPMailer-master/class.phpmailer.php');

    $mail = new PHPMailer(true); // by setting TRUE you enable exceptions
    $mail->IsSMTP(true); // SMTP

    $mail->SMTPAuth   = true;  // SMTP authentication
    $mail->Mailer = "smtp";

    $mail->Host= "xyz"; // Amazon SES
    $mail->Port = 465;  // SMTP Port
    $mail->Username = "xyz";  // SMTP  Username
    $mail->Password = "xyz";  // SMTP Password

    $mail->ClearAllRecipients(); 
    $mail->ClearAddresses();
    $mail->ClearCCs();
    $mail->ClearBCCs();
    $mail->ClearReplyTos();
    $mail->ClearAttachments();
    $mail->ClearCustomHeaders();
    $mail->SetFrom($from, $fromAlias);
    $mail->AddReplyTo($replyTo,$replyToAlias);
    $mail->Subject = $subject;
    $mail->IsHTML(true);  
    $mail->Body    = $html;
    $mail->AltBody = $text;
    $address = $to;
    $addressAlias = $to;
    $mail->AddAddress($address, $addressAlias);
    $mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin@keepity.com>"); 
    $mail->Send();



}

这很奇怪,因为Gmail明确建议在电子邮件中放置List-Unsubscribe头信息,网址为http://support.google.com/a/bin/answer.py?hl=en&answer=81126#unsub - Barmar
2个回答

11

函数addCustomHeader接受两个参数,而不订阅的值格式应为

  <email_to_unscribe@email.com>, <http://url_to_unscribe.com>

这里有一个例子,它应该这样被称呼:

  $mail->addCustomHeader("List-Unsubscribe",'<admin@keepity.com>, <http://keepity.com/?email='.$address.'>');

1
你好,看起来在第一个参数中添加mailto:更好?https://litmus.com/blog/the-ultimate-guide-to-list-unsubscribe $mail->addCustomHeader("List-Unsubscribe",'mailto:admin@keepity.com, http://keepity.com/?email='.$address.''); 这样正确吗? - J. Doe

5

我知道这篇文章有些过时了,但它在谷歌上搜索“List-Unsubscribe”时排名靠前,提供的建议也不太正确。

PHPmailer的addCustomHeader函数只接受一个参数。双引号将整个头部包含起来,如下所示。

$mail->AddCustomHeader("List-Unsubscribe: <mailto:info@example.com?subject=Unsubscribe>, <http://example.com/unsubscribe.php?mailid=1234>");

List-Unsubscribe有两个参数,一个是mailto:,另一个是可以设置为自动退订电子邮件的URL。当然,您也可以动态生成mailid(或称为GET变量)。


2
截至2018年11月26日,addCustomHeader实际上需要两个参数:https://hotexamples.com/examples/-/PHPMailer/addCustomHeader/php-phpmailer-addcustomheader-method-examples.html - Chris S.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接