微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 sendgrid-php.php 中应用 X-SMTPAPI 标头的问题

如何解决在 sendgrid-php.php 中应用 X-SMTPAPI 标头的问题

我尝试以 sendgrid-PHP.PHP 库可接受的方式提供 X-SMTPAPI 标头失败。电子邮件可以发送到 ->addTo 中提供的地址,但我还没有能够应用 ->addHeader 标头方法或 json,因此它被接受并采取行动...正如您所看到的,尝试的 json 数组是远短于允许的 1000 个字符行长度。

有什么帮助或建议吗?

代码如下:

    require_once("/var/www/html/wp-content/plugins/CustomEmailPlugin/sendgrid-PHP.PHP");
    $email = new \SendGrid\Mail\Mail(); 
    $email->setFrom("sawyer@example.com","That EMail");
    $email->setSubject(get_option('EmailSubject'));
    $email->addTo("procinct.net@example.com","Example Recipient");  //
    $email->addHeader('X-SMTPAPI','{"to":["person1@example.io",\n"person2@example.io \n"]}');
    //$email->addTo("bubba@example.xo","Fail Recipient");  //TESTED OK
    //$email->addTo("unsub@example.io","Unsub Recipient"); //TESTED OK
    $email->addContent("text/plain",$txt);
    $email->addContent("text/html",get_option('EmailHTML'));
    $sendgrid = new \SendGrid(get_option('SendgridAPIKey'));
    try {
        $response = $sendgrid->send($email);
        print '<p>Code: ' . var_export($response->statusCode(),true) . "\n<br />Headers: ";
        print_r(var_export($response->headers(),true));  // future: use var_export instead.
        print '</p><br /><p>Body: ' . var_export($response->body(),true) . "\n</p>";
    } catch (Exception $e) {
        echo 'Caught exception: '. $e->getMessage() ."\n";
    }```

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。