This question already has an answer here:
Can Anyone help me with this
SELECT userEmail FROM users in mysql gets a email list like
userEmail
a@gmail.com
b@gmail.com
Currently $userEmail gets first email from the list
a@gmail.com
I am trying to get email list from database like
a@gmail.com,b@gmail.com
<?php
$mailselect = "SELECT userEmail FROM users";
$mailselect2 = mysqli_query($mysqli, $mailselect) or die('-31' . mysqli_error());
$recipients = mysqli_fetch_assoc($mailselect2);
$userEmail = $recipients['userEmail'];
$recipientss = array(',', $row['recipients'] );
$to = 's.gurudharsan@gmail.com';
$subject = "E-mail subject";
$message = 'Testing1: ' . $userEmail . "
" .
'Testing2: ' . implode(',', $recipientss);
$headers = 'From: s.gurudharsan@gmail.com' . "
" ;
$headers .= 'Reply-To: s.gurudharsan@gmail.com' . "
";
mail($to, $subject, $message, $headers);
?>
Currently mail() function sends this email Testing1: a@gmail.com Testing1:
implode(',', $recipientss); This code might be a problem. Anyone with some sugestion
Thanks Guys.
</div>
http://php.net/manual/en/mysqli-result.fetch-assoc.php
Fetch a result row as an associative array
Usage for multiple rows:
$emails = [];
while ($row = mysqli_fetch_assoc($mailselect2)) {
$emails[]=$row['userEmail'];
}
Then $emails
is an array filled with the email addresses, you can implode it.
most simple way is to use mysqli_fetch_all() function is place of mysqli_fetch_assoc(). You will get an array as a result