0
我正在使用sendgrid/sendgrid-phpthe repo on github发送跨国电子邮件。今天我更新了这个库,新版本使用API v3,而之前我使用了v2。我已经改变了代码,按他们的例子,这是我的SendGrid \ Mail对象的转储:SendGrid v3 400错误请求
的问题是,我不断收到400错误的请求错误没有任何额外的信息:
我在做什么错?邮件对象似乎是正确的。
我试图发送电子邮件的方式如下:
$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); ?还是你没有帮助者课程? –
@JustinSteele我按照这个例子使用助手https://github.com/sendgrid/sendgrid-php/blob/master/examples/helpers/mail/example.php,参见kitchenSink函数。即我首先创建邮件对象,然后添加电子邮件,个性化和附件,并调用$ sg-> client-> mail() - > send() - > post($ mail);终于 – Sergey
我不认为'custom_args'参数需要一个JSON数组。我认为它应该是一个JSON对象。像这样:'{“md_email_id”:26921}'。这可能是图书馆的一个问题。显示您如何构建电子邮件对象可能很有用。 –