phpsendgridsendgrid-templates

SendGrid email template style not applying


I'm using SendGrid PHP API to send Newsletter but when I use the template ID, the mail sended doesn't contain the CSS & image.

Here is my code :

<?php
require("sendgrid-php/sendgrid-php.php");

$from = new SendGrid\Email(null, "contact@projet.com");
$subject = "Hello World from the SendGrid PHP Library!";
$to = new SendGrid\Email(null, "me@icloud.com");
$content = new SendGrid\Content("text/plain", "hello");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$mail->setTemplateId("727274bc-XXXX-XXXX-XXXX-83a2b53597e5");

$apiKey = 'SG.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->headers();
echo $response->body();

?>

Hope someone will help me Thanks


Solution

  • Solved ! Just change $content = new SendGrid\Content("text/plain", "hello"); to $content = new SendGrid\Content("text/html", "hello");