Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 add html to MailMessage->line

I like to add some html tags to the body of my mail using MailMessage like this:

$mailMessage = new MailMessage();
$mailMessage->line(trans('mail.someLine') );

In mail.php:

'someLine' => 'Bla bla <a href="html://someurl">html://someurl</a>'

But in the actual mail the entire line comes out as plain text.

I've tried to use html_entity_decode but without any success:

 $mailMessage->line(html_entity_decode(trans('mail.someLine')));

Seems like the line method does it's own encoding. Is there a workaround for this?

ps The rest of the mail has proper html so that's not the point!

update: $mailMessage->action won't do in this case. Let say it should work for something like this as well: $mailMessage->line('Bla bla <strong>something strong</strong> bla');

like image 565
Arno van Oordt Avatar asked Dec 22 '16 12:12

Arno van Oordt


1 Answers

Better to use HtmlString class.

use Illuminate\Support\HtmlString;

return (new MailMessage)
  ->line(new HtmlString($someHtmlBody));

Line will be show as processed HTML code.

like image 82
Artur Anyszek Avatar answered Oct 25 '22 14:10

Artur Anyszek