【问题标题】:unable to send email as both plain text and html in cakephp无法在 cakephp 中以纯文本和 html 格式发送电子邮件
【发布时间】:2015-12-27 18:05:04
【问题描述】:
    App::uses('CakeEmail', 'Network/Email');
    $Email = new CakeEmail();
    $Email->to($emailContentArray['To']);
    $Email->from(array($emailContentArray['From'] => Configure::read('FROM_NAME')));
    $Email->subject($emailContentArray['Subject']);
    $Email->emailFormat('both');
    $response=$Email->send($emailContentArray['Body']);

如果我们检查生成的电子邮件,它看起来像:-

Content-Type: multipart/mixed; boundary="782f009f669cbcf2faafff59fe0eeb5d"
Content-Transfer-Encoding: 8bit
X-Identified-User: {:test25.xyzzzz.com:testttt.com} {sentby:program running on server}

--782f009f669cbcf2faafff59fe0eeb5d
Content-Type: multipart/alternative; boundary="alt-782f009f669cbcf2faafff59fe0eeb5d"

--alt-782f009f669cbcf2faafff59fe0eeb5d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

<div>​<BR>Hi<BR><BR>Soon you will reach the action limit. To keep yourself updated please pay the payment.<BR><BR> Happy to&nbsp; have you<BR><BR>Thanks,<BR>Apps Team<BR>​</div>


--alt-782f009f669cbcf2faafff59fe0eeb5d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<div>​<BR>Hi<BR><BR>Soon you will reach the action limit. To keep yourself updated please pay the payment.<BR><BR> Happy to&nbsp; have you<BR><BR>Thanks,<BR>Apps Team<BR>​</div>

在文本/纯文本中,电子邮件不应显示 html 标签 - 我怎样才能正确发送 html 和纯文本?

【问题讨论】:

  • $emailContentArray['Body'] 是什么?它似乎是一个 html 字符串。

标签: php email cakephp


【解决方案1】:

用base64编码内容和主题: "=?utf-8?b?".base64_encode($s)."?=";

在发送邮件之前不要忘记设置标题:

'Content-Transfer-Encoding: base64';

如果我没记错的话,你可以设置标题:$Email-&gt;setHeader('X-Content-Transfer-Encoding', 'base64');

你可以看看Cakephp sending UTF-8 Emails and lineLengthhttp://book.cakephp.org/2.0/en/core-utility-libraries/email.html

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 2021-04-12
    • 1970-01-01
    • 2012-04-29
    • 2016-03-07
    • 2015-09-19
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多