【问题标题】:save textarea into database and send email keeping the text area format将 textarea 保存到数据库并发送保持文本区域格式的电子邮件
【发布时间】:2013-03-14 20:43:06
【问题描述】:

通过 cakephp,我将一个文本区域保存到数据库中,该文本区域将用作电子邮件消息。 我可以正确保存它,但是当我尝试从数据库中提取数据并使用该数据发送电子邮件时,我收到的电子邮件是一长行文本,而不是保持我在文本中键入的格式区域。是否可以保留发送电子邮件的格式?

例如:如果在文本区域中我输入了类似的内容:

This is line 1.
This is line 2.
This is line 3.

我收到的邮件是

This is line 1. This is line 2. This is Line 3.

我想要的是我输入的内容:

This is line 1.
This is line 2.
This is line 3.

这是代码: App::uses('CakeEmail', '网络/电子邮件');

    $recipients = str_replace(' ', '', $recipients);
    $recipients = explode(',', $recipients);
    $email = new CakeEmail();
    $email->from($user_email);
    $email->to($recipients);
    $email->subject($final_subject);
    $email->template('download_link_email');
    $email->emailFormat('both');
    $email->viewVars(array('url' => $this->generateUrl('datas', 'download', $group_id, $user_id, $email_id), 'final_subject' => $final_subject, 'final_recipient' => $final_recipients, 'final_message' => $final_message));
    $email->send(); 

还有 download_link_email 模板

<html>
    <head>
        <title><?php echo $final_subject; ?></title>
    </head>
    <body>
        <h1><?php echo $final_subject; ?></h1>
        <p><?php echo $final_message; ?></p>
        <p><?php echo $this->Html->link('Click here to download', $url);?>.</p>
    </body>
</html>

至于文本区域如何保存到数据库,是标准的 cakephp 风格

【问题讨论】:

    标签: php mysql email cakephp cakephp-2.0


    【解决方案1】:

    你需要做这样的事情:

    $order   = array("\r\n", "\n", "\r");
    $replace = '<br />';
    $final_message = str_replace($order, $replace, $final_message);
    

    您可以查看here 了解有关 str_replace 的更多信息

    或者你可以使用nl2br(感谢eggyal指出)

    nl2br($final_message)
    

    【讨论】:

    • 不知道那个,但似乎大致相同
    猜你喜欢
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 2015-07-21
    相关资源
    最近更新 更多