Laravel 5添加HTML到电子邮件 [英] Laravel 5 adding HTML to email
问题描述
< br />
元素)我想插入电子邮件。我使用以下代码发送电子邮件: Mail :: send(array('html'=>' email.newinvoice'),array('text'=> $ emailtext),function($ message)use($ email,$ subject,$ contact_company)
{
$ message-> to $ email,$ contact_company) - > subject($ subject);
});
所以 $ emailtext
变量包含一些文本与HTML标签。在我的 emails.newinvoice
布局视图中,我有以下内容:
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html>
< head>< / head>
< body>
< p> {{{$ text}}}< / p>
< / body>
< / html>
发送电子邮件时,我的邮件中插入的文字和该文本中的HTML元素显示为正常字符意味着我的电子邮件显示如下:
test< br /> test
而不是
test
test
如何确保插入的文本中的HTML标签被呈现为HTML和不是纯文本?
您需要指定 html
第一个参数:
Mail :: send(['html'=>'emails.newinvoice'],['text '=> $ emailtext],
// ^^^^
模板中的 {{}}}
与未转义的 {!! !!}
< p> {!! $ text !!}< / p>
/ pre>
I'm currently trying to create a HTML email in Laravel 5 and I have some text (which contains
<br/>
elements) I want to insert in the email. I use the following piece of code to send the email:Mail::send(array('html' => 'emails.newinvoice'), array('text' => $emailtext), function($message) use ($email, $subject, $contact_company) { $message->to($email, $contact_company)->subject($subject); });
So the
$emailtext
variable contains some text with HTML tags. In myemails.newinvoice
layout view, I have the following:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head></head> <body> <p>{{{ $text }}}</p> </body> </html>
When sending the email, the inserted text in my mail and the HTML elements in that text are displayed as normal characters which means that my email shows up like:
test<br/>test
Instead of
test test
How can I make sure that the HTML tags in the inserted text get rendered as HTML and not as plain text?
解决方案You need to specify
html
key in the first parameter:Mail::send(['html' => 'emails.newinvoice'], ['text' => $emailtext], // ^^^^
Also replace auto-escaped block
{{{ }}}
with unescaped{!! !!}
in the template:<p>{!! $text !!}</p>
这篇关于Laravel 5添加HTML到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!