问题
I'm trying to apply the sendgrid templates by building the SendGrid X-SMTPAPI headers in my index.php.
This is an abstract of my index.php code:
// Start Sendgrid
$sendgrid = new SendGrid('userid', 'pwd');
$header = new Smtpapi\Header();
$filter = array(
'templates' => array(
'settings' => array(
'enabled' => 1,
'template_id' => 'f2c99ace-87af-2618-8390-c19e2ad2805f'
)
)
);
$header->setFilters($filter);
$emailwelcome = new SendGrid\Email();
$emailwelcome->addTo($email)->
setFrom('hello@world.com')->
setFromName('Welcome to World')->
setSubject('Your Invitation')->
setText('Hello World!')->
setHtml('<strong>Hello World!</strong>');
$sendgrid->send($emailwelcome);
To apply the templates, as copied from the SendGrid documentation:
"Enabling a Template To use a Template Engine template when you send, enable the templates filter and set the template_id to one of your Template Engine templates.
Example
{
"filters": {
"templates": {
"settings": {
"enable": 1,
"template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"
}
}
}
}
You can use this JSON in the X-SMTPAPI header of an SMTP message, or in the x-smtpapi parameter of a mail.send API call."
Question is... where is the X-SMTPAPI header of my SMTP message? In my composer.json or index.php or in the vendor files?
Thanks for your help.
回答1:
Okay, so apparently. All you need to do is add these 2 lines of code in the index.php:
addFilter('templates', 'enable', 1)->
addFilter('templates', 'template_id', 'f2c99ace-87af-3618-8390-c19e2ad2805f');
Weeeeeeeee~
来源:https://stackoverflow.com/questions/27763303/sendgrid-smtp-api-for-applying-template