我正在创建一个函数来使用 phpMailer 库向用户发送通知电子邮件。
public function notify($address,$subject = '',$body = null,$mailer_options = array()) {
try {
$phpmailer = new PHPMailer($exceptions = true);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPKeepAlive = true;
//$phpmailer->SMTPDebug = true;
$phpmailer->IsHTML(true);
$phpmailer->Host = ...
$phpmailer->Username = ...
$phpmailer->Password = ...
$phpmailer->From = ...
$phpmailer->FromName =...
$phpmailer->AddAddress($address);
$phpmailer->Subject = $subject;
$phpmailer->Body = $body;
$phpmailer->Send();
$phpmailer->ClearAllRecipients();
}
如果我只是发送一封电子邮件或在课堂内发送多封电子邮件,它工作正常。但如果这样做
for($i=0;$i<3;$++)
{
$notification = new $Notification();
$notification->notify(...);
}
它返回一个空白页。没有错误,消息,什么都没有。在你问我之前,我已经打开了 display_errors。
会是什么?
如果我只有一个这样的 phpmailer 实例,它工作正常:
$phpmailer = new PHPMailer($exceptions = true);
(...)
for($i=0;$i<3;$i++)
{
$phpmailer->AddAddress('address');
$phpmailer->Subject = "";
$phpmailer->Body = "sasa";
$phpmailer->Send();
$phpmailer->ClearAllRecipients();
}