Mail From Database

Hello there I have my code below, I basically have a little script that is working, but not how i want it to. When i run the script it is sending it to all the email addresses in the database however it is printing all the names and email addresses to everyone? Im guessing I need to throw a loop in there somewhere or split the array, i’m not entirely sure. Can anyone give me a push in the right direction?

[php]

$result = mysql_query(“SELECT * FROM mail_list”);

while($row = mysql_fetch_array($result)){
$names[] = $row[‘name’];
$addresses[] = $row[‘email’];
}
$to = implode(", “, $addresses);
$recipitent = implode(”, “, $names);
$subject = “We Are Live”;
$from = "[email protected]”;
$headers = “From:” . $from;

$message = "Dear " . $recipitent . “Welcome to our site!”;

mail($to, $subject, $message, $headers);

[/php]

So I wanted to send out the emails individually to each person?

Is there anyone that can help me with this i’ve tried to create a loop that goes through all of the database id’s but I can’t get it right :frowning:

[php]
$result = mysql_query(“SELECT * FROM mail_list”);

while($row = mysql_fetch_array($result)){

$subject = “We Are Live”;
$from = "[email protected]";
$headers = “From:” . $from;

$message = "Dear " . $row[‘name’] . “Welcome to our site!”;

mail($row[‘email’], $subject, $message, $headers);
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service