views:

619

answers:

3
<?php include("admin/db.php"); 
$recipients = "SELECT * FROM recipients ORDER BY id DESC";
$email_list = $db->query($recipients);
foreach($email_list as $row) {
    echo $row['email'].","; 
}

$to = "?";

?>

Above I have a comma delimitated list of emails which I need to insert into the $to variable. How do I do this?

A: 
<?php include("admin/db.php"); 
$recipients = "SELECT * FROM recipients ORDER BY id DESC";
$email_list = $db->query($recipients);
foreach($email_list as $row) {
$to = $row['email'];
$subject = "Subject";
$body = "Message";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
}
?>

Careful with this though, if you database is too big and you are sending 1000's of emails, your host might not like it.

Sam152
A: 
foreach($email_list as $row) {
    echo $row['email'].","; 


  mail($row['mail'], $subject, $body)

}
Asinox
A: 

Hi thanks for the input...

The script is working beautifully. The script says that the messages have been sent but I don't get anything in my email. I have a feeling this has something to do with the php.ini file but I don't know what to change in there. Please advise.