0

Cakephp を使用して、メール メッセージとして使用されるテキスト領域をデータベースに保存します。正しく保存できますが、データベースからデータを取得し、そのデータを使用して電子メールを送信しようとすると、受信した電子メールは、テキストに入力した形式を維持するのではなく、1 行の長いテキストになります。範囲。メールを送信するフォーマットを維持することは可能ですか?

例: テキスト領域に次のように入力した場合:

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', 'Network/Email');

    $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スタイルです

4

1 に答える 1

1

次のようなことをする必要があります:

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

str_replace の詳細については、こちらを確認してください。

または、 nl2brを使用できます(指摘してくれたeggyalに感謝します)

nl2br($final_message)
于 2013-03-14T21:00:03.680 に答える