TFK*_*300 0 php email curl sendgrid
我已经设置了以下内容:
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);
Run Code Online (Sandbox Code Playgroud)
问题是,它不会发送到我的受者$to_emails阵列和输出阵列中的'价值"缺少目标电子邮件"这确实输出我通过电子邮件的阵列,但它仍然是寻找.’ -我我想知道为什么以及如何解决这个问题?据我所知,我已经密切关注了Sendgrid文档 - https://sendgrid.com/docs/Code_Examples/php.html.
如果我取消注释'to'行,它会将电子邮件发送到example@example.com就好了.
小智 5
即使使用该to参数,目前也始终需要该参数.我们建议将其设置为地址.如果存在,API将忽略常规参数.SMTPAPI tofromSMTPAPI toto
您链接的示例显示了当前和状态的参数to和x-smtpapi参数
...电子邮件将发送到example1@sendgrid.com和example2@sendgrid.com.正常地址example3@sendgrid.com将不会收到电子邮件.
| 归档时间: |
|
| 查看次数: |
721 次 |
| 最近记录: |