freephoneid Posted February 18, 2009 Share Posted February 18, 2009 Hi, I've written a PHP program which sends an email to every1 using mail() PHP function by entering body in the text area. Now, since there are more than 5000 receipients, I do not want my PHP page to wait till it sends all email. Can any one tell me how to just trigger the mail function & then get the control back to the next line in my PHP program so that I can display the message in front end saying that the mail is triggered. In the background, the email send process should be continued.... Appreciate your help!! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/ Share on other sites More sharing options...
freephoneid Posted February 18, 2009 Author Share Posted February 18, 2009 Hello, Can anyone help me? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765676 Share on other sites More sharing options...
Q695 Posted February 18, 2009 Share Posted February 18, 2009 Be patient Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765680 Share on other sites More sharing options...
MatthewJ Posted February 19, 2009 Share Posted February 19, 2009 Are you sending the mail yourself? I only ask because most ISP's will not allow more than 200 emails per hour. Also, have you verified that it will send 5000 emails before the script times out even if it the only thing the script does? I imagine it hard to send "test emails" to 5000 people, but maybe you could time the sending of 25 and extrapolate. Not sure if anyone else has a better answer for the continue to next line thing, but the only way I could think to do this would be with process forking (basically running the script to send the mail in another php thread) which I know works under Linux, not sure about Windoze. Again, there are many here brighter than me, but it may be a place to start googling Happy hunting! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765695 Share on other sites More sharing options...
freephoneid Posted February 19, 2009 Author Share Posted February 19, 2009 Hi, I've created a page where it displays text area. In text area, I'll type the message which I want to send to my customers (5000+). Once I click submit, I'm invoking mail() command to send an email to the customer. Since there are 5000+ customers, the page will time out....So, what I want is that when I click submit, it should start sending email to these customers in another background process & instead of wait time, the page should display that "Mail has been trigeered"...In the background, the email sending should continue.... How can I do it in PHP? You mentioned about fork...How can exactly use it? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765697 Share on other sites More sharing options...
MatthewJ Posted February 19, 2009 Share Posted February 19, 2009 What I was saying is before you dive head long into coding for this, you may want to make sure your ISP will allow it... I have not seen unrestricted email in years. but here is a link to php process forking http://www.electrictoolbox.com/article/php/process-forking/ Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765698 Share on other sites More sharing options...
freephoneid Posted February 19, 2009 Author Share Posted February 19, 2009 Yes. they allows us...Whenever my company releases new features for our product, we need to send email notification to our customers & we've more than 5000 customers..... I looked at this URL but it says that we cannot use that approach using web server.....I'm running my application using Apache & is a web based application under Linux.....Will it work? Is there any otehr way to send email notification? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-765702 Share on other sites More sharing options...
freephoneid Posted February 20, 2009 Author Share Posted February 20, 2009 Hi, I tried the command line php to send the email to 5000 customers but I'm not able to invoke it as a separtate process $command = "echo '$MessageBody' ¦ `/var/www/html/ers/emailsender.php >/dev/null &`"; exec($command); The above code works but the page waits for it to get completed....Can any one help???? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767357 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 Take a look at the different exec functions. If you cannot find anything there, you may want to look into threading, as I believe that is what this is doing (not sure I never looked into multi-threading with php before). There should also be a way you can start a unix command and send it to it's own process (again google may help and I do not know if this is possible). Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767363 Share on other sites More sharing options...
freephoneid Posted February 20, 2009 Author Share Posted February 20, 2009 well, many ppl have asked this questions how to execute the script in backgorund but nobody was able to anwer it perfectly (( Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767369 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 exec('wget -b ... >> /dev/null 2>&1 &'); Found this online, maybe it will be helpful to you $command = "echo '$MessageBody' ¦ `/var/www/html/ers/emailsender.php >> /dev/null 2>&1 &'`"; Maybe that will work. Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767384 Share on other sites More sharing options...
freephoneid Posted February 20, 2009 Author Share Posted February 20, 2009 Nop...it didn't help either....Its not invoking the emailsender.php at all with that command... can u pleaseeee help? Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767397 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 The command just looks weird to me either way, try invoking it with the PHP CLI and see what happens: $command = "/usr/bin/php -f /var/www/html/ers/emailsender.php"; The only other way I would recommend is setting up a Cron Job to run this script, this way it is ran in the background on a routine schedule without you having to put this in a script etc. Go Here for an explanation/tutorial on how to set that up. Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767400 Share on other sites More sharing options...
freephoneid Posted February 20, 2009 Author Share Posted February 20, 2009 i'm taking email template as input front end....cron job won;t wrk here... Quote Link to comment https://forums.phpfreaks.com/topic/145819-how-to-trigger-mail-get-to-next-program-line-in-php/#findComment-767405 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.