dongma7796 2017-03-30 12:02
浏览 39

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

My PHPMailer seems to work, but loops through the mailer only 6 times instead of 24 times. if loop used without mailer, it does return 24 addresses. I'm connected to an internal network with access from outside. can anyone clear up what is going on. ($link -> close()) is done at a later stage. also the 24 emails sent two 2 different email accounts(for testing purposes), both receive 3 emails from this phpMailer. found many posts regarding phpMailer, I haven't encountered this one so far.

        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条回答 默认 最新

  • dongliuxia9495 2017-03-30 13:36
    关注

    You're not checking that addAddress succeeds, for example if the email addresses are invalid. If you set SMTPDebug = 2, you can watch the SMTP conversation.

    Check addresses like this:

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

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答