My code works (email is sent) without the line with setTemplateId() method, whenever I try to use a template, email is not sent.
I follow example from https://github.com/sendgrid/sendgrid-php/blob/master/USE_CASES.md#transactional_templates with both cases: "With Mail Helper Class", "Without Mail Helper Class".
$from = new SendGrid\Email(null, "[email protected]");
$subject = "I'm replacing the subject tag";
$to = new SendGrid\Email(null, "[email protected]");
$content = new SendGrid\Content("text/html", "I'm replacing the body tag");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$mail->personalization[0]->addSubstitution("-name-", "Example User");
$mail->personalization[0]->addSubstitution("-city-", "Denver");
$mail->setTemplateId("myTemplateId...");
$apiKey = 'myApiKey';
$sg = new \SendGrid($apiKey);
try {
$response = $sg->client->mail()->send()->post($mail);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Hello @moontrv,
Are you getting any exception message? If so, what is it?
With Best Regards,
Elmer
Hi, thanks.
It turns out that we setup an account which expire the trial period, so that email with template will not be sent. I tried with another newly-created sendgrid account and email with template can be sent.
Thanks for following up @moontrv!
Most helpful comment
Hi, thanks.
It turns out that we setup an account which expire the trial period, so that email with template will not be sent. I tried with another newly-created sendgrid account and email with template can be sent.