使用此功能通过邮件枪发送批量邮件
`//发送批量邮件 公共函数BatchMail($ subject = null,$ body = null,$ record = null) { #实例化客户端。 $ mg =新的Mailgun(MAILGUN_KEY); $ domain = MAILGUN_DOMAIN;
# Next, instantiate a Message Builder object from the SDK, pass in your sending domain
if(!empty($record))
{
$batchMsg = $mg->BatchMessage($domain);
# Define the from address.
$batchMsg->setFromAddress(FROM_EMAIL, array("first"=>FIRST_NAME, "last" => LAST_NAME));
# Define the subject.
$batchMsg->setSubject($subject);
# Define the body of the message.
$batchMsg->setHtmlBody($body);
# Next, let's add a few recipients to the batch job.
foreach ($record as $key => $rec) {
$batchMsg->addToRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
}
$batchMsg->addCcRecipient("mayname@mycompany.in", array("first" => "Sally", "last" => "Doe"));
$re = $batchMsg->finalize();
$result = $batchMsg->getMessage();
$log = $mg->get("$domain/log");
$respbody = $log->http_response_body;
$result = $mg->get("$domain/stats",array('event' => array('sent', 'opened')));
$resp = $log->http_response_code;
//$event = $mg->get("$domain/events");
$response = array("log"=>$log,"result"=>$result,"body"=>$respbody,"code"=>$resp);
return $response;
}
}`
这里的邮件发送正常,但我的cc邮件有问题。
$batchMsg->addCcRecipient("mayname@mycompany.in", array("first" => "Sally", "last" => "Doe"));
此功能用于添加CC邮件。邮件正常传送但邮件正在恢复,标题为To:mayname@mycompany.in,Cc:mayname@mycompany.in。但收件人邮件未列在标题中。
通常gamil会像这样在标题中显示收件人 to:test@gmail.com cc:myname@mycompany.in
任何人都知道为什么邮件枪显示这样的问题?
答案 0 :(得分:0)
替换:
foreach ($record as $key => $rec) {
$batchMsg->addToRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
}
使用:
foreach ($record as $key => $rec) {
$batchMsg->addBccRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
}
或者,如果您希望收件人知道还有谁通过电子邮件发送,请不要使用批处理邮件构建器。请参阅the mailgun API documentation中的“收件人”参数以获取正确的格式。
批处理构建器用于发送许多不同的电子邮件,而不是用于向许多不同的收件人撰写单个电子邮件。 MailGun可能没有预料到您会以这种方式向多个收件人发送电子邮件,因此没有对此错误的测试报道。您可以尝试在their github page上提交错误报告。
有关您尝试实施的规范的更多详细信息可能会带来更好的答案。