There are already many questions about it, but the answers I found are not clear or contrasting, while the problem, even if stated in many ways, seem IMHO to be a general one (and I have it too).
When you have hundreds to thousands recipients for your email (usually with attachments), which is the best way to follow?
I am using AddBcc (see my code above) but I've met many issues during the year, because many recipients find the mail in the spam, many simply do not receive it (or so they say), many have issues with attachments and so on.
Here the suggestion seem to use a single email with as many AddBcc as the recipients, but here we see that "SMTP RFC (RFC 5321) does not impose any limit on BCC field length, though some ISP may limit it intentionally to prevent spamming." and we find a suggestion to send one mail for recipient.
On the other hand here we find that "I'm pretty sure it's actually built into the email protocol that you can't detect which are successful. Otherwise, this information could be used maliciously to discover email addresses for spamming purposes.", so what can I do to ensure everybody to get their email?
Moreover, here we see someone strongly suggesting one email for recipient, pointing out to the PHPmailer wiki article on sending to lists which says (amongst other interesting things) "If the messages you send are absolutely identical, you can add all the addressees using addBCC(), which will mean you only need to send() a single message, though most mail servers will have a limit on the number of addresses you can send at once."
So, if there is no theoretical limit to Bcc number, but "some" mail servers "may" have a limit on that number, and we cannot even know which email arrived and which not, focusing on reliability, what should I do?
<?php
// database connection and session init
require 'main.php';
//mailer init
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('myadd@mysite.gov.it');
//query
$q="SELECT email FROM ".$genitori_table.",".$users_table." WHERE cf_g is not null";
$q=$q." AND ".$users_table.".id_g1=".$genitori_table.".id AND ".$users_table.".stato=1";
while($row = $retval->fetch_array()){
echo $row['email'];
$mail->AddBCC($row['email']);
//$mail->addAddress($row['email']);
}
$mail->isHTML(true);
$mail->Subject = 'my subject';
$mail->Body = 'my body';
$mail->AltBody = 'my alt body.';
$mail->AddAttachment('LetteraAiGenitori.pdf','lettera');
$mail->AddAttachment('AutorizzazioneUscitaAutonomaAlunni.pdf');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>