Cannot send mail including HTML tags in it using Laravel

Viewed 55

I want to send an email with HTML tags inside it with Laravel for which I am using Mail::raw() method. I don't want to send a view, just want to send data as text with few HTML tags in it.

I used to below code

\Mail::raw("<h1>Hello</h1>", function ($message) use ($receiversEmail, $subject, $body) {
            $message->from("hello@user.com", 'A user');
            $message->to($receiversEmail);
            $message->subject($subject);
        });

But the HTML tags are not getting converted and hence I got a mail that reads like

<h1>Hello</h1>

How can i achieve this?

2 Answers

What about this

\Mail::send([], [], function ($message) use ($receiversEmail, $subject, $body) {
            $message->from("hello@user.com", 'A user');
            $message->to($receiversEmail);
            $message->subject($subject);
            $message->setBody("<h1>Hello</h1>", 'text/html');
        });

Use Mail::send instead.

$html = "<h1>Hello</h1>";
\Mail::send([], [], function ($message) use ($receiversEmail, $subject, $html) {         
        $message->from("hello@user.com", 'A user');
        $message->to($receiversEmail);
        $message->subject($subject);
        $message->setBody($html, 'text/html');
    });
Related