I am just working with phpmailer. I would like to generate multiple messages and send them to multiple recipients. However, the generateMessage function() just send to the first recipient in recipient list. Here is my code, any helps is appreciate.
require_once("class.phpmailer.php");
set_time_limit(0);
$wh = implode("', '", $abc);
echo "aaa" . $wh;
//echo $email;
$db = DB::getInstance();
$query1 = $db->query("SELECT * FROM tablea WHERE Location IN ('$wh')");
$result1 = $query1->results();
$query2 = $db->query("SELECT * FROM tableb WHERE Location IN ('$wh')");
$result2 = $query2->results();
$query3 = $db->query("SELECT * FROM tablec");
$result3 = $query3->results();
foreach ($result3 as $b) {
$username = $b->email;
$password = $b->password;
$Times = $b->P2_Time;
}
$minutePerDay = (24 * 60) / $Times;
echo $minutePerDay;
foreach ($result1 as $r) {
$TimeP2SendE = $r->Timea;
break;
}
foreach ($result2 as $r) {
$TimeP2SendG = $r->Timea;
break;
}
$currentTime = date('Y-m-d H:i:s');
$TimeDifferentE = (strtotime($currentTime) - strtotime($TimeP2SendE)) / 60;
$TimeDifferentG = (strtotime($currentTime) - strtotime($TimeP2SendG)) / 60;
if ($TimeDifferentE >= $minutePerDay or $TimeDifferentG >= $minutePerDay) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = $username;
$mail->Password = $password;
$mail->AltBody = " ";
$mail->From = $username;
$mail->FromName = 'Noti';
$mail->clearAddresses();
$mail->AddAddress($email);
$mail->Subject = $title;
$mail->IsHTML(true);
$mail->Body = '<html><body>';
$mail->Body .= "<h3>Information </h3>";
$mail->Body .= '<table class="table table-border">';
$mail->Body .= "</table>";
$mail->Body .= "</body></html>";
if (!$mail->Send()) {
echo "Error sending: " . $mail->ErrorInfo;
} else {
echo "Letter is sent";
}
}
I have run this function 4 times to send to 4 different recipients, however it just sends to the first recipient.