I have more than 10K email id is my database. I am trying to send them email with php mailer. Problem is my hosting provider allow 60 emails per minute.
So, i am thinking i need to change my email code to limit 60 email per minute.
Here is the code i have written so far.
$result = $mysqli->prepare("SELECT uid,email FROM users where address IS NULL and city IS NULL");
$result->execute();
$result->store_result();
$result->bind_result($uid,$email);
while ($result->fetch()){
$email = $email;
--Code to send email--
}
I thought to put sleep command in for loop but i read somewhere that it is bad practice.
I checked this question PHP sleep delay
and found we can use AJAX for the same.
You could use Ajax. And use a timeout to call your PHP script every few seconds. This will avoid the slow script loading. And also you can keep doing it constantly (the current for loop will only run for 33 seconds and then stop).
Is there any advise how can i implement AJAX or any other way to achieve this.