如何使用PHP从数据库发送邮件到多个电子邮件列表

i am working on script to send a mail to a list of emails from my table using php

presently i run a query on the table and echo all the emails meeting such requirements from the sql query

sql="SELECT * FROM people WHERE status in('member','client')"; 
$result = mysql_query($sql)or die("Cannot query orders_products data" . mysql_error()); 

while($row=mysql_fetch_array($result)) { 
    $list = array();
$list[] = $row['Email']; 

echo implode(",",$list);

$email = 'xxxxxxxxxxx'; 
$emailto = implode( "," ,$list ); 

$subject = "xxxxxxxxxxxxxxxx"; 

$headers = "From: $email";

$body .= ++$i.") ".$row['title'] ."

"; 
} 
$body .= "Regards

"; 

$body .= "xxxxxxxxxxxxxxxxxx

";

$send = mail($emailto, $subject, $body, $headers); 

when i try passing these emails to a mail function snippet the mail sending fails.

Please what could i be doin wrong, i need help

Update :

$list[] = $row['Email']; 

    echo implode(",",$list);

all the emails are displayed

But without commas.

$emailto = implode( "," ,$list ); 

i use the same method of imploding the array of data gotten from

$list[] = $row['Email'];

By fail i just mean i was hoping since the emails got echoed using the implode it would all successfully pass the emails to $emailto and then send a mail to each of them.

So, what I think you're trying to do is to get the email address from your table where the user is either a member or a client. Then, you have a from address, subject, and a body. In addition, it looks like maybe you're trying to add to the body some unique information. Finally, I think you want to send an individual email to each user, separately.

You could modify your code to be like this:

<?php
$sql="SELECT * FROM people WHERE status in('member','client')";
$result = mysql_query($sql) or die("Cannot query orders_products data" . mysql_error());

$emailContent = 'xxxxxxxxxxx';
$emailSubject = 'xxxxxxxxxxx';
$body = 'xxxxxxxxxxxxxxx';
$headers = "From: from@email.com";

while ($row = mysql_fetch_array($result)) {
  // optionally modify body here...?
  $emailBody = $body .= $row['title']; // or whatever you're trying to do here...

  // send email to each individual person
  mail($row['Email'], $emailSubject, $emailBody, $headers);
}

I think this is how you'd modify your code to get it to do what you're asking.