I'm new to SendGrid and I'm trying to work out why the emails are always sent as plain text instead of the designed HTML transactional template I've made. If I use the sendgrid "preview/test" feature to send myself the email, it comes through looking exactly how it should, images, HTML etc.
However, when I use the PHP API to send the email, the email is sent but only in plain text. I use this line to tell SendGrid which template to use:
$mail->setTemplateId([my template ID]);
Are there some other things I should be setting via the PHP API before I finally call the following?
$sg->client->mail()->send()->post($mail);
Below is all my SendGrid code:
$from = new SendGrid\Email([website name], [website email address]);
$subject = "test subject";
$to = new SendGrid\Email(null, $email);
$content = "";
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$mail->setTemplateId([my template ID]);
//$mail->setASMGroupId(3057);
$mail->personalization[0]->addSubstitution("%email%", $email);
$mail->personalization[0]->addSubstitution("%hash%", $hash);
$apiKey = [my api key];
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
I dont put anything in for the $content because the content is dictated in the template.
If anyone has any idea why it's only sending a plain text version of my templated email when sent from PHP, any advice would be much appreciated.
Thank you
EDIT
I thought I might have to set the content-type in the header so I added:
$mail->addHeader("Content-Type", "text/html");
But this just gives me an error. Is there something I'm missing?