用于应用模板的SendGrid SMTP API [英] SendGrid SMTP API for Applying Template

查看:152
本文介绍了用于应用模板的SendGrid SMTP API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过在index.php中构建SendGrid X-SMTPAPI头来应用sendgrid模板。



这是我的index.php的一个抽象代码:

  //启动Sendgrid 
$ sendgrid = new SendGrid('userid','pwd');
$ header = new Smtpapi\Header();
$ filter = array(
'templates'=>数组(
'settings'=>数组(
'enabled'=> 1,
' template_id'=>'f2c99ace-87af-2618-8390-c19e2ad2805f'


);
$ header-> setFilters($ filter);
$ emailwelcome = new SendGrid\Email();
$ emailwelcome-> addTo($ email) - >
setFrom('hello@world.com') - >
setFromName('欢迎来到世界') - >
setSubject('Your Invitation') - >
setText('Hello World!') - >
setHtml('< strong> Hello World!< / strong>');
$ sendgrid-> send($ emailwelcome);

应用从SendGrid文档复制的模板:



启用模板
发送时使用模板引擎模板,启用模板过滤器并将template_id设置为您的一个模板引擎模板。



示例

  {
filters:{
templates:{
settings:{
enable:1,
template_id:5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f
}
}
}
}

SMTP邮件的X-SMTPAPI标头中的JSON或mail.send API调用的x-smtpapi参数中的JSON。



问题是。 .. 我的SMTP邮件的X-SMTPAPI标头在哪里?在我的composer.json或index.php或供应商文件中?



解决方案

好的,很明显。所有你需要做的是在index.php中添加这两行代码:

  addFilter('templates','enable ',1) - > 
addFilter('templates','template_id','f2c99ace-87af-3618-8390-c19e2ad2805f');

Weeeeeeeee〜


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.

解决方案

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~

这篇关于用于应用模板的SendGrid SMTP API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆