• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

PHP script - Auto submit

I have the following script (attached).

Basically, it allows you to send a message to a specific number of users at a time (to avoid server overload). For example, if I want to send a message to 2000 users, I can set it to send to 500 users at a time. However, i have to manually click "next page" 4 times to send to all 2000 users.

I'd like to avoid having to click "next page' for every 500 users and have it do it automatically, with a timer.

For example, once i click 'submit', it will send to 500 users........ countdown from 30 seconds.....send again, countdown from 30 seconds....until the script is finished.

I believe javascript is the right road.
1 Solution
Hmm.. a possible way would be to check if the submit button has been hit and if it has send a header to reload the page and remove the users from the mail list who have been sent the message.

you would also check to see if the number of users to send the message to != 0 so that it doesnt keep reloading the page.

something like

//pseudo code
isset ( post 'submit'  && numuserstosendemailto >0) {
header('refresh: 30; url=thecurrentpage')


You can do this by using JavaScript and AJAX.
In the javascript use setTimeout() method as below:
// In the sendMessage() function use the ajax to call a php page which will send messages to 500 users at a time. The second parameter in the setTimeout() is the milliseconds value after whish a function will get called (5,000 milliseconds or 5 seconds).
Ray PaseurCommented:
You should be able to do all of this in plain old PHP.  Modify the logic in the script to do something like this:

Count the total number of users who are to receive the email.

While that value is a positive integer...
   Send some number (maybe 500 like your example)
   Subtract the number sent from the total number
End While.

A single initiation of the script would be sufficient to send all the messages.  

You will want to know about the PHP time limit for your script (see set_time_limit man page at php.net) and you will want to consider what happens if the script fails and has to be restarted.  Maybe an indicator in the data base would be appropriate to keep track of the email messages you have sent.

You should also consider the consequences of ignore_user_abort() no matter what method you use.

And finally, you want to be sure to comply with the law.  Some of the penalties for violating this act involve handcuffs!

Best wishes for the new year, ~Ray
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

techempireAuthor Commented:
I could be wrong, but the "next page' button isnt even visible/clickable unless the script functions correctly. Therefore adding additional checking seems unnecessary.

isnt there a way to just simply add code to automatically click the "next page' button (or what have you) after a 30 second countdown? And ignore compliance?
Ray PaseurCommented:
"...code to automatically click the "next page' button..."

Perhaps you could use CURL to cause the script to restart itself.  I would not take a chance on a countdown timer - it might miss the mark, then you would lose the ability to restart.  Instead I would go with a predictable and dependable way to re-initiate the process for the next group of email addresses.
techempireAuthor Commented:
can we please close, no real solution
Ray PaseurCommented:
What did you expect for a solution?  Please post the code you have tried so far - perhaps we can help if we can see what progress you have made toward the solution.  Thanks and regards, ~Ray

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now