PHPMailer破坏了While循环

时间:2016-07-30 19:31:22

标签: php while-loop phpmailer

我想使用PHPmailer在while循环中向多个人发送电子邮件。但是一旦循环到达行include '../email/PHPMailerAutoload.php';,它就会在while循环内停止。完整代码看起来像这样

<?php
    $result = $con->prepare('SELECT * from table WHERE Date = ?');
    $result->execute([$Date]);
    while($row = $result->fetch(PDO::FETCH_BOTH)){
        $Email=$row['Email'];   
        include '../email/PHPMailerAutoload.php';
        email_function($Email);
    }
?>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

PHPMailerAutoload.php必须包含/调用一次!请试试这个:

include '../email/PHPMailerAutoload.php';
$result = $con->prepare('SELECT * from table WHERE Date = ?');
$result->execute([$Date]);
while($row = $result->fetch(PDO::FETCH_BOTH)){
    $Email=$row['Email'];   
    email_function($Email);
}