Reputation: 21
I'm trying to send automated emails with mail(). It sends some emails but not all, around 50%. To test I'm using the same email address for all emails, and still only some get delivered.
I'm using localhost XAMPP.
Here's the code:
if ($_POST['sendEmail'] == "SEND Email") {
ob_start();
$buffer = str_repeat(" ", 4096);
$buffer. = "\r\n some HTML \r\n";
set_time_limit(0);
$noEmails = $last - $first + 1;
echo "Emails sent (of $noEmails):";
for ($index = $first; $index <= $last; $index++) {
$to = $email["$index"];
$subject = "Hey {$firstName["
$index "]}!";
$message = "$emailMessage";
$headers = 'From: [email protected]'."\r\n".'Reply-To: [email protected]'."\r\n".'X-Mailer: PHP/'.phpversion();
sleep(1);
mail($to, $subject, $message, $headers);
echo $buffer.$index;
ob_flush();
flush();
}
ob_end_flush();
}
Please give your suggestions.
Upvotes: 1
Views: 1282
Reputation: 1
For sending bulk emails you can set a cron job which may run after 5 or 10 minutes that will send only a small quantity of emails at a time. Create a reference in a table that so you can have record of which addresses have been emailed. The whole bulk will be divided into little chunks and as it will be running in background it will not put a huge load on your SMTP server. You should use PHP Mailer or SwiftMailer libraries.
You can have a look at this question to select which php mailing library is best:
Hope this helps.
Upvotes: 1