我正在尝试使用Sendgrid PHP API(https://github.com/sendgrid/sendgrid-php)从php循环发送电子邮件。但是,脚本只会发送第一封电子邮件,循环将不会继续。
我有一个像这样定义的邮件功能:
function sendgrid($assoc_number,$to_email,$subject,$message,$HTML_message,$type) {
require "sendgrid-php/sendgrid-php.php";
$sendgrid = new SendGrid("api-key-removed");
$email = new SendGrid\Email();
$email
->setSmtpapiTos($to_email)
->setFrom($from_email)
->setSubject($subject)
->setText($message)
->setHtml($HTML_message)
->setCategories($type);
;
$sendgrid->send($email);
}
真正的循环要复杂得多,但在发送第一封邮件后也会停止:
$assoc_number = 10;
$to_email = array("me@mydomain.ca");
$subject = "Testing SendGrid loop";
$message = "Testing SendGrid loop.";
$HTML_message = "Testing <strong>SendGrid</strong> loop.";
$type = array("Test");
$i = 0;
while ($i<3) {
$i++;
sendgrid($assoc_number,$to_email,$subject,$message,$HTML_message,$type);
echo $i . "<br>";
}
发送第一封电子邮件后循环停止的原因有何提示?