ERROR - Bulk email

-2

I did a bulk email trigger, everything works fine, however the while only runs with the first email selected. I did not understand why ...

Note: The query () is a function that I created to reduce the size of the code.

$query = query("SELECT email FROM emails");

while ($row = $query->fetch(PDO::FETCH_ASSOC)) {

    $query1 = query("SELECT enviado FROM emails WHERE email = '".$row['email']."'");
    $row1 = $query1->fetch();

    $query2 = query("SELECT * FROM msg WHERE id = '".$row1['enviado']."'");
    $row2 = $query2->fetch();

    include "settings/mail.php";
    require 'PHPMailer/class.phpmailer.php';

    // Iniciar o SMTP
    $mail= new PHPMailer;

    // Define Charset
    $mail->CharSet = 'UTF-8';

    // Ativar SMTP
    $mail->IsSMTP();

    // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
    $mail->SMTPDebug = false;

    // Autenticação ativada
    $mail->SMTPAuth = true;

    // SSL REQUERIDO pelo GMail
    $mail->SMTPSecure = 'ssl';

    // SMTP utilizado
    $mail->Host = $host_smtp;
    $mail->Port = $port_smtp;

    // Conta SMTP
    $mail->Username = $user_smtp;
    $mail->Password = $pass_smtp;

    // Enviador
    $mail->SetFrom($user_smtp, "Nome");

    // Recptor
    $mail->addAddress($row['email']);

    // Mensagem
    $mail->Subject = $row2['title'];
    $mail->msgHTML($row2['msg']);

    // Enviar mensagem
    $mail->send();
}
    
asked by anonymous 15.10.2018 / 05:04

1 answer

0

Change this line:

while ($row = $query->fetch(PDO::FETCH_ASSOC)) {

To:

$row = $query->fetchAll(PDO::FETCH_ASSOC)
while ($row) {

fetch () returns only 1 result. Must use fetchAll ()

    
15.10.2018 / 20:50