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();
}