Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send an email using a SendGrid template with php api?

Tags:

php

sendgrid

I have recently created a template in my SendGrid account which I'd like to use in my php application.

I'm currently sending emails using that account, but I have to code the html right inside my app, which doesn't provide the flexibility I need.

I couldn't find a method in the API to select the template I want to use and to replace the variables....

Any idea?

Thanks

like image 377
Muc Avatar asked Oct 22 '15 13:10

Muc


People also ask

How do I send an HTML email in SendGrid?

Email template with HTML codeClick “Download Template,” and we'll send you a copy of the HTML code to your inbox. You can then copy/paste the code into your email design editor to import the template and tailor it to your brand and campaign.

What is PHP SendGrid?

It provides a cloud-based email delivery service and handle all the heavy lifting involved in sending messages and getting them delivered. We are going to use SendGrid API for sending emails. SendGrid-PHP library helps you in a quick SMTP setting to send emails through SendGrid using PHP.


1 Answers

After digging through GitHub I found this code snippet which works for me... I hope it helps you. To use templates in v3 here is the code:

$mail->setTemplateId("xxxxxxxxxxxxxxxxxxxx");
// Put your template ID in from the web console after you create a template
like image 96
AdheneManx Avatar answered Sep 21 '22 17:09

AdheneManx