Jump to content

Recommended Posts

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!

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!

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!

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/

 

 

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!

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!

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).

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.