I have written a code which sends mail to multiple people. The code was working fine until last few days. The reason the number of persons it was sending mails was around 1500. Infact i was sending mails using Bcc in my mail function.
The problem was that it was not sending mails to all the people. I am maintaining a log file to record number of persons to whom mails are snet etc. The script was either getting timed out or for some reason, whatever it was not sending mails to all the recipients.
Then i broke down the code so that i could send 200 recipients (using Bcc) mail at the same time.
This again has not solved my problem. Has anybody faced this problem earlier? Is there any limits to the Cc and Bcc for mail function? Do i have to user a different format of sending mails.
My code is as below.
$mBcc = $MailMembers; // Comma separated mail members
$iNumAdd = 200;
$ArrBcc = "";
$mailTo = "";
$ArrBcc = explode(",", $mBcc);
$iCount = count ($ArrBcc);
$iIdx = 0;
reset ($ArrBcc);
while ($iCount > 0)
{
$iCnt = 1;
$sTo = "";
while (list ($key, $val) = each ($ArrBcc))
{
if ($iCnt == $iNumAdd)
break;
$sTo .= "$ArrBcc[$key], ";
$iCnt++;
}
$sTo = substr ($sTo, 0, (strlen ($sTo) - 2 ));
$mailTo[$iIdx] = $sTo;
$iIdx++;
$iCount = $iCount - $iNumAdd;
}
for ($i=0;$i<count($mailTo);$i++)
{
$mHeaders = "From: $mFrom\n";
$mHeaders .= "Reply-To: $mFrom\n";
$mHeaders .= "Bcc: $mailTo[$i]\n";
$mHeaders .= "Content-Type: text/html\n";
$mHeaders .= "X-Mailer: PHP/";
$mHeaders .= phpversion();
writetolog ("Sending Mails to $mailTo[$i]");
if (!mail("$mTo", "$mSubject", $mMsg, $mHeaders))
{
$error = "SMTP Mail Error. Some mails might not be sent. Please try again after some time.";
writetolog ("ERROR : $error");
exit;
}
}
Do reply if anybody has an idea.
Bhavesh