无法在cakephp中以纯文本和html身份发送电子邮件

时间:2015-09-30 04:31:58

标签: php email cakephp

    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>

在text / plain中,电子邮件不应显示html标签 - 如何才能正确发送html和纯文本?

1 个答案:

答案 0 :(得分:0)

在base64中对内容和主题进行编码: "=?utf-8?b?".base64_encode($s)."?=";

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

'Content-Transfer-Encoding: base64';

如果我没有错,你可以设置标题:$Email->setHeader('X-Content-Transfer-Encoding', 'base64');

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