我是usign cakephp 2.x和使用电子邮件组件发送电子邮件。
我正在尝试在标题中添加列表-取消订阅。
$this->Email->headers = [
'List-Unsubscribe'=>'<mailto:'.$email_from.'?subject=Remove from Mailing List>, <'.$SITEURL.'unsubscribe?em='.$email_to.'>',
'List-Unsubscribe-Post'=>'List-Unsubscribe=One-Click'
];现在在电子邮件源中,它显示在X-header中。
X-List-Unsubscribe: <mailto:clients@example.com?subject=Remove from Mailing List>, <http://example.com/unsubscribe?em=xyz@example.com>
X-List-Unsubscribe-Post: List-Unsubscribe=One-Click但它没有显示取消订阅链接与来自。
我需要在邮件头列表-取消订阅,以避免垃圾邮件。
当我尝试使用$this->Email->additionalParams时,它不会在电子邮件标题中显示列表-取消订阅。
下面是我使用的代码
$send_from = $email_from_name . "<" . $email_from . ">";
$this->Email->sendAs = 'both'; // text / html / both
$this->Email->from = $send_from;
$this->Email->replyTo = $email_from;
$this->Email->return = $email_from;
$this->Email->to = $email_to;
$this->Email->delivery = 'smtp';
$this->Email->smtpOptions = ['host'=>$imap_server,'port'=>587,'username'=>$email,'password'=>$password];
$this->Email->subject = $subject;
$this->Email->headers = [
'List-Unsubscribe'=>'<mailto:'.$email_from.'?subject=Remove from Mailing List>, <'.SITEURL.'unsubscribe?em='.$email_to.'>',
'List-Unsubscribe-Post'=>'List-Unsubscribe=One-Click' ];
$this->Email->textMessage = $this->_html_to_text($content);
//$this->Email->delivery = 'debug';
$this->Email->send($content);发布于 2020-07-16 23:00:51
电子邮件组件不支持自定义的非X前缀的报头,如果你需要的话,你将不得不使用CakeEmail,它在默认情况下不会给报头加前缀,并要求你在需要的情况下显式地传递前缀的报头。
鉴于,从CakePHP 2的第一个发行版开始,现在可能是您最终放弃它的好时机。
简单明了的例子:
App::uses('CakeEmail', 'Network/Email');
// The transport/connection configuration should probably better be moved into a config file
$Email = new CakeEmail(array(
'transport' => 'Smtp',
'host' => $imap_server,
'port' => 587,
'username' => $email,
'password' => $password
));
$Email
->emailFormat('both')
->template('subscribe')
->from($send_from)
->replyTo($email_from)
->returnPath($email_from)
->to($email_to)
->subject($subject)
->addHeaders(array(
'List-Unsubscribe' =>
'<mailto:' . $email_from . '?subject=Remove from Mailing List>, ' .
'<' . $SITEURL . 'unsubscribe?em=' . $email_to . '>',
'List-Unsubscribe-Post' => 'List-Unsubscribe=One-Click'
))
->send($content);这将需要两个模板,一个用于app/View/Emails/html/subscribe.ctp中的HTML
<?php
// $content contains the data passed to the `send()` method, wrapped to max 998 chars per line
echo $content;一个用于app/View/Emails/text/subscribe.ctp中的文本,要求您将HTML to text转换到模板中。你可能应该使用,下面的代码只是说明了这个原理:
<?php
echo _html_to_text($content);另请参阅
https://stackoverflow.com/questions/62935827
复制相似问题