Frage

So, I am running on a a free webhost 3owl.com. I know that free hosts suck compared to paid but its temporary. Anyways, I have 90 users that need email sent to them.

The issue:

I cannot send them at a speed of more than 1 every 4 seconds.

I must not run the while loop for more than 40 seconds at a time.

So, I need help figuring out how to send the email in sections.

Send email 1
4 second break
Send email 2
4 second break
Send email 3
4 second break
Send email 4
4 second break
Send email 5
4 second break
Send email 6
4 second break
Send email 7
4 second break
Send email 8
4 second break
Send email 9
4 second break
Send email 10
---------------
STOP SCRIPT in a way that doesnt load the website? for 10 seconds
---------------
continue with the next 10

Is this even possible? Maybe some sort of checkbox system which list the users and you can check who you wish to email it to...

Here is my current code

mail_users($_POST['subject'], $_POST['content']);

And the function for that looks like this:

function mail_users($subject, $body) {
    $query = mysql_query("SELECT `email`, `first_name` FROM `users` WHERE `allow_email` = 1");
    while (($row = mysql_fetch_assoc($query)) !== false) {
        email($row['email'], $subject, "Hello ". $row['first_name'] . ",\n\n" . $body);
        sleep(4);
    }
}

I am in great need of help. Maybe some javascript is needed for the checkboxes

War es hilfreich?

Lösung 2

So this is the way I did it (for a long time with a website that had thousands of users)

This is totally a hack, but it works.

Build a page that sends a single email and mark that user as "sent" in the db, eg (sent=1)

Select the next user that is not "sent" (eg sent=0)

Put a meta refresh tag to refresh every minute on the page , open a browser, launch the page and let it run for an hour and a half or even all night...

In the am, clear the db of (set all users sent=0)

(I used to have my scripts run all night... )

Andere Tipps

You can also use JavaScript and use Ajax to call the PHP that sends the mail. Use a setTimeOut to call the script every four seconds and keep track of which email is being sent through query string variables.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top