i'm working on a PHP - jQuery simple script which is sending an email on every PHP.
Here is my code:
<HTML>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<?php
require "./config.php";
ConnectWithMySQLDatabase();
$time = date('h:i:s');
$result = mysql_query("SELECT * FROM `emails`");
while($row = mysql_fetch_array($result))
{
$email = addslashes($row['email']);
?>
<script type="text/javascript">
setTimeout(function() {
$.post( "./Sender.php", { name: "<?PHP echo $email;?>", time: "<?PHP echo $time;?>" })
.done(function( data ) {
$( "#result" ).html( "Email sended to: " + data + "<br>");
});
}, 5000);
</script>
<?PHP
}
?>
<div id="result"></div>
The problem with my code is that it is wating 5 seconds and then it's rushing the sending of the emails in like instant.
- How can i make this script send 1 email on every 5 seconds untill all emails are send?
- How can i make this script show 1 result on 1 line and then the next result the line bellow and so on ? Now the script is printing:
Email sended to:
on just one line and chaning the emails but not making more lines..
Thanks in advance!