mounting an array with php for p phpmailer

Asked

Viewed 408 times

0

Guys I’m trying to set up an array with the list of e-mail addresses, so that phpmailer send them. However I’m having problems.

No error is displayed, php simply does not send the emails.

I’m mounting the array like this:

     // Define os destinatário(s)
        $consulta = $mysqli->query("select email,nome from clientes where status=true");
        while ($resultado = mysqli_fetch_object($consulta)) {

            // Monta o array
            $destinatario[] = array($resultado->email => $resultado->nome);
        }

And send like this:

foreach($destinatario as $email_cliente => $name){
    $mail->AddBCC($email_cliente, $name);
}

Can anyone help me? I think the problem is in the array mount.

1 answer

3


Try to do it that way Hugo:

    // Define os destinatário(s)
    $consulta = $mysqli->query("select email, nome from clientes where status=true");

    while ($resultado = mysqli_fetch_object($consulta)) {
        // Monta o array
        $destinatario[] = $resultado;
    }

    foreach($destinatario as $key => $value){
        $mail->AddBCC($value->email, $value->name);
    }
  • I think this way it works, however and when I want to send an array that is not performed a query in the BD, just like the previous question that you helped me. I need a way to send a list that I mount slect in the BD and tbm with input understands.

  • I don’t quite understand your placement now @Hugoborges. If you take the bank emails you can do it this way. If you mount the array you can do otherwise.

  • An alternative is to standardize the object shape and transform its array if necessary. $Object = (Object) $array;

  • I got it, well I tested it this way and it worked. But my netbeans is saying that the variable $key not being used. What is the need for it?

  • In this case only it is working as a counter even(0,1,2,3 ...). If you were to make some rule could use. You can take if you are not going to use.

  • OK, thank you very much :)

Show 1 more comment

Browser other questions tagged

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