PHP script - Auto submit

Posted on 2009-12-28
Last Modified: 2012-05-08
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.
Question by:techempire
    LVL 5

    Expert Comment

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


    LVL 1

    Expert Comment

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

    Expert Comment

    by:Ray Paseur
    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 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

    Author Comment

    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?
    LVL 107

    Expert Comment

    by:Ray Paseur
    "...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.

    Author Comment

    can we please close, no real solution
    LVL 107

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now