Alok Jethanandani
Alok Jethanandani

Reputation:

PHP Mail $to multiple recipients from database table

<?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?

Upvotes: 0

Views: 3884

Answers (2)

NSP
NSP

Reputation: 41

$recipients = "SELECT * FROM recipients ORDER BY id DESC";
while ($row = mysql_fetch_array($recipients))
{
    $adresses[] = $row['email']; 
}

$to = implode(",",$adresses);

Upvotes: 1

Asinox
Asinox

Reputation: 6865

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


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

}

Upvotes: 0

Related Questions