如何使用 sendgrid 发送电子邮件在 PHP 中设置(html 和 css)电子邮件正文的样式?

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

我正在使用 sendgrid 我想为我发送的电子邮件设置样式,但在电子邮件中他们显示的是原始代码,我不知道为什么。 有什么地方我做错了吗? 这是我写的代码...

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

您的内容类型有误。您必须将其设置为 text/html:

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

否则即使你写html也不会渲染成html。