I am using PHPMailer to send emails with attachments.
Each email takes about 5 seconds to send, and the PHP can send up to 5 emails with a total in that case of 10 PDFs...
During all that time, the browser shows a white page.
<?php
echo '<div>some spinner html</div>';
// code here to send emails
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
echo 'all the rest of the html';
?>
This doesn't work...
I have the feeling I can use an ob_start() to buffer the rest of the page and only show a spinner.
Real answer: Use
JSand create an API usingPHPBest solution to your problem is using
JavaScriptandXHRand make a beautiful UI for it. If you want to show a loading and remove it after emails sent and show other stuff after disappearance of loading, it's only possible throughJS.PHPis just a server side language capable of sending a response to browser and have no access to rendered page!Flush output
Just use
ob_flush()andflush()functions:Using implicit flush
This looks like the previous one, but reduced a function call. this removes the
flush()call!Turn off output buffer
Other solution is to turn off output buffer: