I have a for loop that sends a certain number of emails, but I would like to know how to make that for loop send the emails on a certain time scale:
<?php
$a = 1;
for($i = 1; $i <= 10; $i++) {
$destinatario = "[email protected]";
$asunto = "Hola Diesan";
$cuerpo = "Como estas?";
mail($destinatario,$asunto,$cuerpo);
echo "<h1>Correos enviados</h1>";
}
?>
It occurs to me to do it with javascript's setInvertal(), but I don't know how to integrate it. I don't know much php, and I need this script for something simple in one go.
If you want to do it in PHP from the server side, you can simply use the Sleep function .
If you want the call to be made from js/jquery on the client side, as you say you should use setInterval and an Ajax call , in case you want to keep the execution asynchronous.
You can do it using setInterval() and JQuery. The process is to call your php function from js via JQuery with $.get . The server will execute the function with the for sending the emails.
For example:
JS:
PHP (server.php):
If you try this example, every 3000 millisec. the for is executed on the server and you get as a response: