Phpmailer and foreach

Asked

Viewed 90 times

0

I redid the email from my website.

Among the novelties, you can now send a message to more than one e=mail.

I have this select that searches which emails will be from the recipients:

<?php
/****** E-mails dos destinatários ******/
$sql_email_dest = mysqli_query($config, "SELECT email FROM tb_email_home_email WHERE id_item = '1'") or die(mysqli_error($config));

if(@mysqli_num_rows($sql_email_dest) <= '0'){
    echo "";
}else{
    while($r_sql_email_dest = mysqli_fetch_array($sql_email_dest)){
        $email_email_home_sel[] = $r_sql_email_dest[0];
    }
}   
/****** E-mails dos destinatários ******/   

?>

And on Phpmailer, this foreach to send:

<?php
foreach($email_email_home_sel as $email_contato){
    $mail->AddAddress($email_contato);            // E-mail do destinatário
}   
?>

It’s simple, but I’ve tried many ways...

If I put it the old way, with an email (without being on foreach) it works.

But the way above, no chance.

Has anyone ever seen a similar case?

Have any idea?

  • Hello Rogério Pancini, I ran your script on my server and it worked fine. In the table I put 4 emails and received in 4. The error may be in another part of the code. If you can edit the question by adding the part of phpmailer

  • The error may be in the emails saved in the database, such as special characters. Check that the emails are registered correctly.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.