Home » Php » How to style(html and css) emails body in PHP using sendgrid to send email?

How to style(html and css) emails body in PHP using sendgrid to send email?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am using sendgrid i want to style my sent Emails but at the email they are showing raw code i do not know why. Here is the image i am receiving in my email
Is there somewhere i am doing incorrect or something?
This is the code i wrote …

require 'vendor/autoload.php'; 
$email = new \SendGrid\Mail\Mail();
$email->setFrom("my email address");
$email->setSubject("Welcome");
$email->addTo($EmailAddress);
//Below code where i am having issues
$email->addContent("text/plain", "<img src='Assets/images/logo.png'> Welcome To my channel...");
$sendgrid = new \SendGrid('your api code');
$sendgrid->send($email);
How to&Answers:

Your content type is wrong. You have to set it to text/html:

$email->addContent("text/html", "<img src='Assets/images/logo.png'> Welcome To my channel...");

Otherwise it will not be rendered as html even if you write html.