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: my_account@gmail.com'."\r\n".'Reply-To: my_account@gmail.com'."\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.