Link to home
Start Free TrialLog in
Avatar of techempire
techempire

asked on

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.
hn-masspm.php
Avatar of andoneknight
andoneknight
Flag of United Kingdom of Great Britain and Northern Ireland image

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

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

?>

?>
Avatar of shaziashaikh
shaziashaikh

You can do this by using JavaScript and AJAX.
In the javascript use setTimeout() method as below:
setTimeout("sendMessage()",10000);  
// 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).
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)
   sleep(30);
   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!
http://www.ftc.gov/bcp/edu/pubs/business/ecommerce/bus61.shtm

Best wishes for the new year, ~Ray
Avatar of techempire

ASKER

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?
"...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.
can we please close, no real solution
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial