问题描述
我正在尝试使用sendgrid API发送大量电子邮件。下面是我的PHP脚本,SendGrid文件被正确调用并创建了邮件对象。问题是,当脚本运行时,一次只发送一封电子邮件,并且看起来是随机的。代替example_one @ my_domain.com,example_one @ my_domain.com和example_one@my_domain.com都接收电子邮件,只有一个会收到。在PHP脚本下面,将$ mail作为json对象
$email = new \SendGrid\Mail\Mail();
$email->addTo("example_one@my_domain.com");
$personalization = new Personalization();
$personalization->addTo( new To( "example_two@my_domain.com" ) );
$email->addPersonalization( $personalization );
$personalization = new Personalization();
$personalization->addTo( new To( "example_three@my_domain.com" ) );
$email->addPersonalization( $personalization );
$email->setFrom("send_from@my_domain.com","Sender");
$email->setSubject("This is the email subject");
$email->addContent("text/plain","This is the content");
$sendgrid = new \SendGrid(API_KEY);
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
JSON $ mail对象
{
"personalizations":[
{
"to":[
{
"email":"example_one@my_domain.com"
}
]
},{
"to":[
{
"email":"example_two@my_domain.com"
}
]
},{
"to":[
{
"email":"example_three@my_domain.com"
}
]
}
],"from":{
"name":"Sender","email":"send_from@my_domain.com"
},"subject":"This is the email subject","content":[
{
"type":"text\/plain","value":"This is the content"
}
]
}
有人知道为什么这不能正常工作吗?
我花了相当多的时间浏览示例,并使$ mail对象(转换为JSON)与sendgrid中的https://sendgrid.com/docs/for-developers/sending-email/personalizations/#sending-multiple-emails-from-multiple-senders-to-multiple-recipients个性化示例相同,但仍然无法正常工作。 / p>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)