SendGrid SMTP API for Applying Template

耗尽温柔 提交于 2019-12-11 12:41:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!