【发布时间】:2016-09-05 16:10:19
【问题描述】:
我正在使用 sendgrid/sendgrid-php the repo on github 发送跨国电子邮件。今天我更新了这个库,新的使用 API v3 而我之前使用的是 v2。我已经根据他们的示例更改了代码,这是我的 SendGrid\Mail 对象的转储:
问题是我不断收到 400 BAD REQUEST 错误,没有任何其他信息:
我做错了什么?邮件对象似乎是正确的。
我正在尝试通过以下方式发送电子邮件:
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$request_body = [creating the mail object];
$response = $sg->client->mail()->send()->post($request_body);
【问题讨论】:
-
明确一点,[创建邮件对象];表示新的 SendGrid\Mail($from, $subject, $to, $content); ?还是您没有 Helper 类?
-
@JustinSteele 我按照这个例子使用了帮助器github.com/sendgrid/sendgrid-php/blob/master/examples/helpers/…,参见 kitchenSink 函数。 IE。我首先创建邮件对象,然后添加电子邮件、个性化设置和附件并调用 $sg->client->mail()->send()->post($mail);终于
-
我不认为
custom_args参数需要 JSON 数组。我认为它应该是一个 JSON 对象。像这样:{"md_email_id":26921}。这可能是图书馆的问题。展示您如何构建电子邮件对象可能很有用。