0

I want to wait N seconds after each iteration in the loop below before proceeding to the next iteration. Each iteration sends an email by SMTP and, because the loop will send over 100 emails, I want there to be a short belay between each email being sent. Is this possible to do with PHP?

while ($date = $data) {
    $mail = $date['email'];
    smtp_mailer($mail , $subject, $massage);
}
Brian DeMilia
  • 13,103
  • 1
  • 23
  • 33

1 Answers1

0

I think you are just looking for sleep. If you want to wait 10 seconds after each iteration before the next you would write that as follows:

while ($date = $data) {
    $mail = $date['email'];
    smtp_mailer($mail , $subject, $massage);
    sleep(10);
}
Brian DeMilia
  • 13,103
  • 1
  • 23
  • 33
  • @SarafatRabby No problem. I've edited your question so that it is clearer and to make obvious to others that it is not a duplicate of https://stackoverflow.com/questions/45953/php-execute-a-background-process as someone claimed – Brian DeMilia Dec 26 '21 at 03:36