SEVIZ Posted May 10, 2009 Share Posted May 10, 2009 Hello all. I have a script that runs and lets a user submit a message that is then emailed to anywhere from 5 to 200 people. This is all done with php and while the emails are being sent the page just sits there. Does anyone know a way via php to instead of just sitting there upon submitting, the page goes to a "loading" page and then goes to the final page once the emails are fully sent? Basically once I hit submit I'd like to display some verbage like, "Be patient we are sending the message now". Then once the server is done sending it refreshes to the final page. Anything like this? Possible? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/ Share on other sites More sharing options...
.josh Posted May 10, 2009 Share Posted May 10, 2009 You can echo out a "loading" or "processing" message and use ob_flush to send it to the browser before the script is done executing. Or you could use js/ajax to send the form info bits at a time, displaying progress bar or whatever, as each batch gets sent. Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/#findComment-831159 Share on other sites More sharing options...
SEVIZ Posted May 10, 2009 Author Share Posted May 10, 2009 If I wanted to just echo the text how would I associate it to to echo once submitted? Would I need java? Or can I do that in php? Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/#findComment-831167 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Put echo at the top line of the page the form submits to? Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/#findComment-831169 Share on other sites More sharing options...
.josh Posted May 10, 2009 Share Posted May 10, 2009 okay, the problem with php is that php parses everything and then sends the output (if any) back to the client. So, it is not a "real-time" scripting language. But there are some tricks you can do to fake it, depending on your needs. One trick is flushing what's currently in the output buffer to the browser before the script is done processing. You can do that by echoing whatever message you want, then using ob_flush, then send out the emails. So the message will display before the script is actually done sending emails. Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/#findComment-831184 Share on other sites More sharing options...
SEVIZ Posted May 10, 2009 Author Share Posted May 10, 2009 Would it make more sense to create a loading page from scratch and move all my queries and such to this file? Then on submit instead of running the code in the existing page, I could load the second page which would have the loading dialogue and the email code. Actually this makes perfect sense. I don't know why I didn't do this in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/157624-display-a-loading-page-while-emails-being-sent/#findComment-831193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.