0

phpMailer lib を使用して、通知メールをユーザーに送信する関数を作成しています。

 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 のインスタンスが 1 つだけあれば、問題なく動作します。

$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 $Notificationvariable の値から新しいインスタンスを作成します$Notification。本当に「通知」が含まれている場合にのみ機能$Notificationします(クラスの名前が「通知」であると仮定します)

PHP スクリプトで有効display_errorsにしても、サーバーがデフォルトで無効にしている場合、スクリプトに構文エラーがあってもエラーは表示されません。

于 2010-09-16T10:43:13.007 に答える