3
My question is the following: the code is working as expected the problem when I put a large list of email (100) the page gets all blank "Loading" and only returns me the result after the script finishes running, I need a solution that allows me to show the result as the loop and passing on the screen.
I thought of using jQuery to be able to automate sending 1 by 1 and show the result I think that way the server will not overload.
I don’t know what to do now, but I need a help from at least knowing what to search for and what function to use to load the data dynamically.
The code is this one below:
$email = explode("\n", $to);
$headers .= "From: ".$nome." <".$de.">\r\n";
$message = stripslashes($message);
$i = 0;
$count = 1;
while($email[$i]) {
$ok = "Ok!";
if(mail($email[$i], $subject, $message, $headers))
echo "Aguarde: $count <b>".$email[$i]."</b> <font color=red>Email Enviado </font> <br><hr>";
else
echo "Aguarde!: $count <b>".$email[$i]."</b> <font color=red>Email não enviado. </font><br><hr>";
$i++;
$count++;
}
$count--;
if($ok == "ok")
echo "";
One simple way to solve it is to execute the sending of the emails in the background using cron/schtask and, at each sending, save the result in a database. Through another script would make the queries via ajax. You can see everything in "real time" with a small delay. The problem is the huge amount of requisitions. To reduce this consumption, long-Polling techniques are used but for this case where emails have to be sent as soon as possible, it will be the same. Maybe better a rule where you expect to send 20 or 50 and then return the result of that group in a single request.
– Daniel Omine