user5095266 user5095266 - 4 months ago 22
PHP Question

PHPMailer destroys the While loop

I want to send e-mails to multiple persons in a while loop using PHPmailer. But as soon as the loop gets to the row

include '../email/PHPMailerAutoload.php';
it stops inside the while loop. The full code looks like this

<?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);
}
?>


Any ideas?

Answer

The PHPMailerAutoload.php must be included/called once! Please try this:

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);
}
Comments