简体   繁体   中英

PHP Mail BCC To Multiple Recipients

I am trying to send email to multiple users through BCC fetching email id's from database, For this I have written Below code

$q = $db->query("SELECT group_concat(concat(''',user_email,''')) FROM topic_subscribe");
$recipients = array($q['user_email']);
$headers .= 'BCC: '. implode(",", $recipients) . "\r\n";
$a = mail( null, $subject, $message, $headers );

But it is not sending any email If I take $recipients manually like below it works

$recipients = array("jobs3433@gmail.com","foxhitz@gmail.com",);

may be fetching email id's from database is the problem but can not figure out the problem. any help pls

You shouldn't concatenate quotes to user_email . And you need to give an alias to the group_concat() expression so you can refer to it by name in the returned value.

Then use explode() to split the value at the commas. But if you're just going to call implode() , you could just use the row value as it is.

$q = $db->query("SELECT group_concat(user_email) AS emails FROM topic_subscribe");
$headers .= 'BCC: '. implode(",", $q['emails']) . "\r\n";
$a = mail( null, $subject, $message, $headers );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM