Skip to content
Advertisement

Laravel: HTML in notification

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):

JavaScript

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:

JavaScript

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.

Advertisement

Answer

Well, you can also create a new MailClass extending the MailMessage Class.

For example you can create this class in appNotifications

JavaScript

And then use in your notification:

Instead:

JavaScript

Change it to:

JavaScript

And then you can use content var in your notification views. For example if you publish the notification views (php artisan vendor:publish), you can edit email.blade.php in resources/views/vendor/notifications and append this:

JavaScript

We do it like this and works like a charm 😀

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement