0

我正在创建一个函数来使用 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();
       }
4

1 回答 1

1

$从以下位置删除new Notification

for($i=0;$i<3;$++)
{
   $notification = new Notification();
   $notification->notify(...);
}

new $Notification将从变量的值创建一个新实例$Notification。仅当$Notification确实包含“通知”时才有效(假设您的课程名为“通知”)

如果您已display_errors在 PHP 脚本中打开,但服务器默认已禁用它,则如果您的脚本中存在语法错误,则不会显示错误。

于 2010-09-16T10:43:13.007 回答