I\'m currently trying to create a HTML email in Laravel 5 and I have some text (which contains
elements) I want to insert in the email. I use the fo
After checking various solutions, following codes worked for me -
try {
$template_data = ['otp' => $otp, 'name' => $name];
//send verification code
Mail::send(['html' => 'email.account_verification'], $template_data,
function ($message) use ($email) {
$message->to($email)
->from('test@yourdamin.com') //not sure why I have to add this
->subject('Account verification');
});
return Response::json(['code' => 200, 'msg' => 'Sent successfully']);
} catch (Exception $ex) {
return Response::json(['code' => 200, 'msg' => 'Something went wrong, please try later.']);
}
You need to use:
{!! $text !!}
instead of
{{ $text }}
Blade automatically escapes any html when echoing unless you explicitly tell it not to.
Yeah the solution above work just fine..
use {!! $contents !!}
instead of this
{{ $contents }}
This {!! $contents !!}
is for allowing html
While this {{ $contents }}
is just for 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>