【问题标题】:cakephp 3.x : can we use emailformat='both' without using templatecakephp 3.x:我们可以在不使用模板的情况下使用 emailformat='both'
【发布时间】:2015-12-27 21:28:13
【问题描述】:

发送电子邮件时我使用emailformat='both',但我发送电子邮件时不使用模板。

$Email->reset();
$Email->emailFormat('both');
$Email->to($to);
$Email->send($body);

在原始电子邮件中,我没有收到纯文本:-

--alt-82207de3b13b81a697e6c7c6db145af2
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>Kioui Apps Team<br>​</div>


--alt-82207de3b13b81a697e6c7c6db145af2
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>Kioui Apps Team<br>​</div>

【问题讨论】:

    标签: php email cakephp


    【解决方案1】:

    CakePHP 不提供开箱即用的此类功能。

    理论上,您应该能够在没有模板的情况下使用您自己的自定义渲染(视图)类来实现这一点,该类忽略模板并仅转换内容。

    但这有点 hacky,简单地创建两个不自己添加内容的基本模板会更容易,而只是回显/转换 $content 视图变量,它将保存您传递给 CakeEmail::send() 的任何内容.

    一个简单的例子:

    电子邮件/html/template-name.ctp

    echo $content;
    

    电子邮件/文本/模板名称.ctp

    echo html_entity_decode(strip_tags($content), ENT_QUOTES, Configure::read('App.encoding'));
    

    请注意,这只是一个非常基本的示例,应该演示该概念,它不是以任何方式正确的 HTML 到文本的转换,您应该使用/构建一个专用的 HTML 到文本的转换器来正确净化和转换输入!

    参见例如 Converting HTML to plain text in PHP for e-mail

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 2019-04-28
      • 2016-02-23
      • 2011-02-23
      • 2023-04-09
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多