I'm using the default notification system (Laravel 5.3) to send an email. I want to add HTML tags in message. This does not work (it displays the strong tags in plain text):
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Info')
->line("Hello <strong>World</strong>")
->action('Voir le reporting', config('app.url'));
}
I know it's normal because text is displayed in {{ $text }}
in the mail notification template. I tried to use the same system as in csrf_field()
helper:
->line( new \Illuminate\Support\HtmlString('Hello <strong>World</strong>') )
But it does not work: it displays strong as plain text.
Can I send HTML tags without changing the view? (I don't want to change the view: protecting text is OK for all other cases). Hope it's clear enough, sorry if not.
Run php artisan vendor:publish
command which will copy email.blade.php
to resources/views/vendor/notifications
from vendor
directory.
Open this view and change {{ $line }}
to {!! $line !!}
in two places. In Laravel 5.3 these are 101
and 137
lines in the view.
This will display unescaped line
strings which will allow you to use HTML tags in notification emails.
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