Reputation: 1862
I am trying to send email using SMTP in Laravel everything is good but the html elements is coming along in the email body.
i.e.,
I am getting the below as mail
<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>
Instead of
Hello user
Thanks
Here is my Code :
What is the thing i am missing to make it applied on the content of the email
$msg = "<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>"
$message->setBody($msg);
$message->to('[email protected]');
$message->subject('Welcome Mail');
Upvotes: 2
Views: 4459
Reputation: 802
Seems like you want to send an email as HTML format:
mail($to, $subject, $message, $headers);
You will have to use the $headers
parameter.
The last parameter, the headers, are optional for the function but required for sending HTML email, as this is where we are able to pass along the Content-Type declaration telling email clients to parse the email as HTML.
Or, if you just want to add breaking lines and you leave HTML elements:
$msg = "Welcome \n Hello user \n Thanks"
Upvotes: 0
Reputation: 214
Try this...
$msg = "Welcome
Hello user
Thanks"
$message->setBody($msg);
$message->to('[email protected]');
$message->subject('Welcome Mail');
Upvotes: 1
Reputation: 919
One possible solution is to wrap your HTML code in body tag. Take a look at Laravel mail api too.
Upvotes: 0