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