[英]SendGrid X-SMTPAPI is being ignored in my header request file being sent out to sendgrid
[英]Sendgrid x-smtpapi errors with 'missing destination email'
我设置了以下内容:
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$file = date('YmdHis');
$fp = fopen('/var/www/mydir/files/'.$file.'.csv', 'w');
$url = 'http://sendgrid.com/';
$user = 'myuser';
$pass = 'mypass';
$to_emails = array(
'to' => array(
'1@example.com','2@example.com','3@example.com'
),
'category' => 'Test'
);
$fileName = $file;
$filePath = dirname(__FILE__);
$params = array(
'api_user' => $user,
'api_key' => $pass,
'x-smtpapi' => json_encode($to_emails),
//'to' => 'example@example.com',
'subject' => 'Test email',
'html' => '<p>Testing sendgrid mail</p>',
'text' => 'sent',
'from' => 'me@example.com',
'files['.$file.'.csv]' => '@'.$filePath.'/files/'.$fileName.'.csv'
);
print_r($params);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
print_r($response);
//unlink('./files/'.$file.'.csv');
mysql_close($connect);
问题是它不会发送到$to_emails
数组中的收件人并输出“缺少目标电子邮件”。它确实输出了我传递的电子邮件的数组,但仍在数组中寻找“收件人”值-我不知道为什么,我该怎么解决,我跟着Sendgrid文档密切,据我可以看到- ? https://sendgrid.com/docs/Code_Examples/php.html 。
如果我取消注释“收件人”行,它将电子邮件发送到example@example.com就好了。
即使始终使用SMTPAPI to
当前始终也需要to
参数。 我们建议将其设置为from
地址。 如果存在SMTPAPI to
,则该API将忽略常规to
参数。
你链接到同时显示了例子to
和x-smtpapi
参数和目前的状态
...电子邮件将同时发送到example1@sendgrid.com和example2@sendgrid.com。 普通用户example3@sendgrid.com将不会收到电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.