CakePHP电子邮件呈现问题

时间:2014-12-12 07:18:28

标签: php cakephp html-email cakephp-2.3

我在myproject中使用 CakeEmail 发送htmlmail。我在电子邮件布局文件中使用表结构并将可替换文本保存在数据库中。 Mail功能正常,它在发送之前将数据库内容添加到电子邮件布局。但是当我收到邮件时,表格布局正在破碎。我发现CakeEmail.php中的render函数将<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>',     

如何在没有<p>元素的情况下发送替换数据库文本。

数据库条目就像这样

<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>               

1 个答案:

答案 0 :(得分:2)

行包含在默认HTML电子邮件元素模板中的<p>个元素中,可以在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;