How to send Mail to email addresses in mysql table
Posted: Thu May 21, 2015 7:38 am
Hello Friend,
I tried sending mail to the 30 email addresses in mysql table with the below code. But the problem am having is that, the code is sending the same mail to all the emails 30 times.
I also tried something like this but still gave the same result.
Pls what's the way out
Thanks
I tried sending mail to the 30 email addresses in mysql table with the below code. But the problem am having is that, the code is sending the same mail to all the emails 30 times.
Code: Select all
$get_emails = mysql_query("SELECT email FROM customers");
while($row = mysql_fetch_array($get_emails)){
$email = $row[email];
mail($email, $sub, nl2br($message), $headers);
}
Code: Select all
$get_emails = mysql_query("SELECT email FROM customers");
$all_emails = array();
while($row = mysql_fetch_array($get_emails)){
$all_emails[] = $row[email];
}
foreach($all_emails as $to_email){
mail($to_email, $sub, nl2br($message), $headers);
}
}
Thanks