PHPMailer不会返回错误,但只发送6封电子邮件而不是24

时间:2017-03-30 12:02:16

标签: php email smtp phpmailer

我的PHPMailer似乎可以工作,但是通过邮件程序只循环6次而不是24次。如果循环使用没有邮件程序,它确实返回24个地址。我已连接到内部网络,可以从外部访问。任何人都可以清理正在发生的事情。 ($ link - > close())在稍后阶段完成。另外24封电子邮件发送了两个2个不同的电子邮件帐户(用于测试目的),都从这个phpMailer收到3封电子邮件。发现很多关于phpMailer的帖子,到目前为止我还没遇到过这个帖子。

        if ($result = $link->query("SELECT Adres FROM Emails")) {
            //Alle variabelen voor de mail
            $mail = new PHPMailer;
            //$mail->SMTPDebug = 3;                               // Enable verbose debug output
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->SMTPKeepAlive = true;
            $mail->Host = 'smtp-mail.outlook.com';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = '**********@outlook.com';                 // SMTP username
            $mail->Password = '**********';                           // SMTP password
            $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587;                                    // TCP port to connect to
            $mail->setFrom('**********@outlook.com');
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = 'APP';
            $mail->Body    = 'is this working??';
            $mail->AltBody = 'is this working??'; 
            while($row = mysqli_fetch_row($result)) {
                $variable = $row[0];
                $mail->addAddress($variable);

                if(!$mail->send()) {
                    echo 'Message could not be sent.';
                    echo 'Mailer Error: ' . $mail->ErrorInfo;
                } else {
                    echo 'Message has been sent';
                }
                $mail->ClearAllRecipients( );   
            }
            $result->close();   
        }

1 个答案:

答案 0 :(得分:0)

您未检查addAddress是否成功,例如电子邮件地址无效。如果您设置SMTPDebug = 2,则可以观看SMTP会话。

检查这样的地址:

$variable = $row[0];
if (!$mail->addAddress($variable)) {
  echo "skipping invalid address $variable";
  continue;
}