I have been having problem using phpmailer to send bulk emails, no problem with a single email though.
here is my code:
$result = mysql_query("select * from $to",$conn) or die("list
selected ($to) does not exist ".mysql_error());
while ($row = mysql_fetch_array($result))
{
$email[] = $row['email'];
$student[] = $row['name'];
}
foreach ($email as $val => $uemail) {
$email = $uemail;
$students= $student[$val] ;
require("class.phpmailer.php");
$mail = new PHPMailer(true);
try {
$mail->AddReplyTo('info@bratim.com', 'My Name');
$mail->AddAddress("$email", "$student");
$mail->SetFrom('info@me.com', 'MyName');
$mail->AddReplyTo('info@me.com', 'My nameg');
$mail->Subject = "$sub";
$mail->MsgHTML("Dear $student<br> $msg <br>
<img src=\"$path\"> <p>
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE.
***DO NOT RESPOND TO THIS EMAIL****
");
$mail->AddAttachment("$path2"); // attachment
$mail->Send();
echo "Message Sent OK to $email </p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
Any help, suggestion will be appreciated.
you assign
$student[$val]to$studentsinside the foreach but then you assignthe array
$studentto your phpmailer object:shouldn’t it be
other than that is a bad pratice to instantiate a new mailer object for each email you have to send, you should just cicle on the dynamic variables like
AddAddressand keep all the other outside to avoid overload , and remember to clear the variables that will change, like theAddAddress, like this: