how to send mails individually instead of sending to all recipients together?
my code is:
function SendMail($msg,$subject,$addresses)
{
require "class.phpmailer.php";
//Fetch from email here
foreach($addresses as $key=>$val){
$email = test_input($val);
if((trim($email)=='') || (!filter_var($email, FILTER_VALIDATE_EMAIL))){
unset($addresses[$key]);
}
}
$addresses=array_unique($addresses);
$row = FetchAllsettingsCustomMailchmp();
//end fetch
$mail = new PHPMailer();
$mail->PluginDir = "";
$mail->Host = "localhost";
$mail->From = $row['email_from'];
$mail->FromName = $row['sitename'];
$mail->Subject = $subject;
foreach ($addresses as $address)
$mail->AddAddress($address);
$mail->MsgHTML($msg);
$mail->IsHTML(true);
$mail->AltBody ="Order";
$mail->CharSet = 'UTF-8';
$success = $mail->Send();
$try = 1;
while((!$success)&&($try<1)&&($mail->ErrorInfo!="SMTP Error: Data not accepted"))
{
sleep(5);
$success = $mail->Send();
$try++;
}
$mail->ClearAddresses();
if(!$success)
return false;
else
return true;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}