mimi mimi - 5 months ago 61
PHP Question

PHPMailer adding multiple emails to BCC from MYSQL

In below code, we are first selecting users based on the admin's input from database. Then sending emails to those users. With the code it sends emails to

test user. But for the bcc part is not working, as it doesn't send any emails to bcc email users.

foreach($email_array as $news_mail){

This is how we fetch user emails via form & PHP prepare statement with mysqli.

Here is the main part code:

$email_array[] = $news_mail;
// echo "successful";
echo "database failed";
//--Email Sending Starts
$mail_news = new PHPMailer;
$mail_news->Host = EMAIL_HOST;
$mail_news->SMTPAuth = true;
$mail_news->Port = EMAIL_PORT;
$mail_news->SMTPSecure = 'tls';
$mail_news->Username = EMAIL_ADD;
$mail_news->Password = EMAIL_PASS;
$mail_news->From = EMAIL_ADD;
$mail_news->FromName = 'Company Account';
foreach($email_array as $news_mail){
$mail_news->WordWrap = 50;
// $mail_news->SMTPDebug = 2;
$mail_news->Subject = "".$sub;
$mail_news->Body = "".$body;
$mail_news->AltBody = "".$altbody;

if(!$mail_news->send()) {
echo "Failed Sending Emails" ;
echo 'Mailer Error: ' . $mail_news->ErrorInfo;
} else {
echo "All Email sending completed" ;

$msn->close(); // Finally closing the database

Answer Source

You need to change the line $mail_news->AddBCC($news_mail.";"); with $mail_news->AddBCC($news_mail); because the method addBCC() handles the semicolon by itself. You do not need to specify by your own.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download