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 my emails.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>
You need to use:
{!! $text !!}
instead of
{{ $text }}
Blade automatically escapes any html when echoing unless you explicitly tell it not to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With