Php 用于应用模板的SendGrid SMTP API

Php 用于应用模板的SendGrid SMTP API,php,json,email,templates,sendgrid,Php,Json,Email,Templates,Sendgrid,我试图通过在index.php中构建sendgrid X-SMTPAPI头来应用sendgrid模板 这是我的index.php代码的摘要: // Start Sendgrid $sendgrid = new SendGrid('userid', 'pwd'); $header = new Smtpapi\Header(); $filter = array( 'templa

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

这是我的index.php代码的摘要:

            // 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); 
您可以在SMTP邮件的X-SMTPAPI标头或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');

Weeeeeee ~

如果有帮助的话,在SendGrid上有一些模板服务,例如sendwithus.com或customer.io。根据您的使用情况,可能值得检查一下。
addFilter('templates', 'enable', 1)->
addFilter('templates', 'template_id', 'f2c99ace-87af-3618-8390-c19e2ad2805f');