Won*_*nka 3 php laravel laravel-5 laravel-5.3
我通过通道发送一封电子邮件toMail,该电子邮件是从文本区域保存的,在该文本区域中我按 Enter 键两次换行,因此在输入中看起来像这样:
Line 1
Line 2 with space above and below
Line 3
Run Code Online (Sandbox Code Playgroud)
当我在邮件中使用该文本时,如下所示:
return (new MailMessage)->subject('test spacing')
->line($this->text);
Run Code Online (Sandbox Code Playgroud)
电子邮件中看起来像这样:
Line 1 Line 2 with space above and below Line 3
Run Code Online (Sandbox Code Playgroud)
我更改了相关部分email.blade.php:
@foreach ($introLines as $line)
{{ $line }}
@endforeach
Run Code Online (Sandbox Code Playgroud)
到:
@foreach ($introLines as $line)
{!! nl2br(htmlspecialchars($line)) !!}
@endforeach
Run Code Online (Sandbox Code Playgroud)
但这仍然不起作用。在notificationsdb中的表中,保存为:
Line 1\n\nLine 2 with space above and below\n\nLine 3
Run Code Online (Sandbox Code Playgroud)
知道如何让发送的电子邮件显示间距,使其不只是一大块吗?
更新:
因此在表中laravel插入通知,但实际上它是这样保存在表中的:\n\nnotificationsmodel
这是传递给 的内容email,但仍然不确定如何在 中获取这些空格email。
您的输入文本包含换行符,Laravel 将自动删除这些换行符(请参阅基于该类formatLine()的方法)。您可以子类化 MailMessage 并覆盖格式:Illuminate\Notifications\Messages\SimpleMessageMailMessage
class CustomMailMessage extends MailMessage {
protected function formatLine($line) {
if (is_array($line)) {
return implode(' ', array_map('trim', $line));
}
// Just return without removing new lines.
return trim($line);
}
}
Run Code Online (Sandbox Code Playgroud)
或者您可以在将文本发送到 MailMessage 之前拆分文本。由于“line”方法接受字符串或数组,因此您可以拆分行并将它们一次性全部传入:
return (new MailMessage)->subject('test spacing')
->line(array_map('trim', preg_split('/\\r\\n|\\r|\\n/', $this->text)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7652 次 |
| 最近记录: |