I am trying to build a bulk subscriber mailer program for my client. The hosting that my client uses has very strict policies about outgoing mails. Therefor I need to be very cautious about the volume and frequency.
At first, I tried to send all the emails in same go (around 500 subscribers), but that was giving me timeout error as well as mails were not sent. What I am trying to accomplish is send 50 mails, wait for an hour and again send 50 mails, keep repeating the process until all the mails are sent. My code works for the first lot only. I have no idea how to sleep the process and wake it up after 1 hour.
I searched Google and SO for help, but none of them seems have solution for this particular model. Here is my code.
function process_mails() {
set_time_limit(0);
$i=0;
foreach ( $mails as $mail ) {
$i++;
// My mailer code here. Removed it for simplicity
if ($i > 0 && $i % 50 == 0) {
sleep(3600);
}
}
}
The problem is, this code sends the first 50 emails correctly, but doesn't send the remaining batch. Where I am doing wrong?
EDIT: Using third-party scripts/framework is not an option (the client is strictly against it), otherwise SwiftMailer was a perfect solution.