Hi zonkd,
If I understand you correctly, am I wrong in thinking you are looking for something along these lines then:
// Construct your SQL statement for retrieving a list of
// email addresses and execute the query at this point.
// assign it to $result for example (use mysql_fetch_array, I think, when retrieving from the database)
$list = array();
$subject = "The subject line of our email";
$message = "The main message body\n";
$headers .= "From: My Senders name<user@some.company.co.uk>\n";
$headers .= "X-Sender: <user@some.company.co.uk>\n";
$headers .= "X-Mailer: PHP\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <user@some.company.co.uk>\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
// Forgotten why I've added this to an array only to loop
// through it again, but perhaps it was for simplicity at the
// time.
foreach($result as $row){
$list[] = $row['db_column_name_that_holds_email_addresses'];
}
for($i=0;$i<count($list);$i++){
// mail the recipients, spinning this through a
// loop so that other users addresses don't show
// up in the To: fields. Could always just fire
// off one mail, but you never know how big the
// user list will be.
if(!mail($list[$i], $subject, $message, $headers)){
// The $messages array is something I use throughout my code
// for passing success/error messages around, but you could simply
// print this back to the screen for each mail that failed, which,
// depending on the size of your list, could be quite large!!
$messages['mail_failed'] = "There was a problem sending the email to the users.\n";
}
else{
$messages['mail_sent'] = "All ".count($list)." users have been mailed\n";
}
}
Keep in mind that the mail() function is a wrapper around your machines MTA (usually Sendmail I believe) and, if I remember correctly, goes through a series of processes whereby it waits for a response from the desitnation host before moving on the next recipient, so, with a large list of users to mail, this could lead to some noticeable delays while it waits for a response, but again, it could be quite nippy depending on how much of a queue the MTA can hold and how things are processed on your host server.
Anyhow, hope that is what you're looking for and gets the ball rolling.