I am trying to send email to all the members email id's which is stored in the database. Here is the code
<?php
$sql = mysqli_query($con,"select email from email_list where email");
//$recipients = array();
while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) {
$recipients[]= $row['email'];
}
$to = $recipients;
$repEmail = 'abc@gmail.com';
$subject = "$title";
$body = "$description";
$headers = 'From: xyz <'.$repEmail.'>'. "\r\n";
$headers .= 'Reply-To: abc@gmail.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
if (mail($to, $subject, $body, $headers)){
echo "<script>alert('Email sent')</script>";
}
else {
echo "<script>alert('Email failed')</script>";
}
?>
In this above code email goes to 1 person.