I'm using PHPMailer to send emails. I've use it inside a foreach loop in order to send an email to a list of recipients.
It is working, because the email is being sent, but each recipient receives the whole list of recipients!
foreach ($id as $item) {
$mail->addAddress($item);
$mail->Subject = $correo['mailAsunto'];
$mail->Body = $correo['mailMensaje'];
if(!$mail->send()) {
echo 'Error: ' . $mail->ErrorInfo;
} else {
echo 'Mail sent to '.$item.'<br>';
}
}
I've tried: $mail->AddBCC($item);
instead of addAddress
but the email can still be seen in the "TO" header.
What may I do? This can have serious privacy implications.
UPDATE
Just in case anyone has a similar issue, after the responses received, here's how the code is now:
foreach ($id as $item) {
$mail->addAddress($item);
$mail->Subject = $correo['mailAsunto'];
$mail->Body = $correo['mailMensaje'];
if(!$mail->send()) {
echo 'Error: ' . $mail->ErrorInfo;
} else {
echo 'Mail sent to '.$item.'<br>';
$mail->ClearAddresses();
$mail->ClearAllRecipients();
}
}