【问题标题】:CakePHP email rendering issueCakePHP 电子邮件渲染问题
【发布时间】:2014-12-12 07:18:28
【问题描述】:

我在我的项目中使用 CakeEmail 发送 htmlmail。我在我的电子邮件布局文件中使用了一个表结构,并将我的可替换文本保存在数据库中。邮件功能工作正常,它在发送前将数据库内容添加到电子邮件布局中。但是当我收到邮件时,表格布局正在中断。我发现 CakeEmail.php 中的渲染函数在我保存在数据库中的每一行代码中添加了<p> 标签。

(int) 32 => '   <table  align="center" border="0" cellspacing="0" cellpadding="0" >',
(int) 33 => '   <tbody> <tr><td><p> <tr></p>',
(int) 34 => '<p>  <td style="padding:0;margin:0;"></p>',
(int) 35 => '<p>  <h2 style="color:#404040;font-size:24px;font-weight:bold;line-height:22px;padding:0;margin:0;letter-spacing:0.015 em; font-family: arial,sans-serif;">Activate Account</h2></p>',
(int) 36 => '<p>   </td></p>',
(int) 37 => '<p>   </tr></p>',
(int) 38 => '<p> </p>',
(int) 39 => ' <tr><td></tbody>',
(int) 40 => ' </table>',     

如何发送没有&lt;p&gt; 元素的替换数据库文本。

数据库入口是这样的

<table style="margin-top: 80px" width="630" align="center" border="0" cellspacing="0" cellpadding="0" >                                 <tbody>                                                              <tr><td style="padding:0;margin:0;">                                                                                <h2 style="color:#404040;font-size:24px;font-weight:bold;line-height:22px;padding:0;margin:0;letter-spacing:0.015 em; font-family: arial,sans-serif;">Activate Account</h2>                                                                            </td></tr></tbody>                                                                </table>               

【问题讨论】:

  • 恕我直言,如果您的代码示例中的某些空白列将被删除,它会增加可读性(对于这个问题)。
  • 检查您的&lt;tr&gt; 标签。第 33 行有 2 个开口,第 39 行有另一个开口。
  • 这与标签无关,它发生在单个 tr 行中。我认为这是因为蛋糕用&lt;p&gt; 标签呈现换行符

标签: php cakephp html-email cakephp-2.3


【解决方案1】:

在默认的 HTML 电子邮件元素模板中,行被包裹在 &lt;p&gt; 元素中,可以在 app/View/Emails/html/default.ctp 中找到:

$content = explode("\n", $content);

foreach ($content as $line):
    echo '<p> ' . $line . "</p>\n";
endforeach;

https://github.com/cakephp/cakephp/blob/2.3.0/app/View/Emails/html/default.ctp

根据你的需要修改模板,可能你只想echo $content;

【讨论】:

    猜你喜欢
    • 2012-06-03
    • 2011-01-02
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2012-04-05
    • 2018-07-19
    相关资源
    最近更新 更多