-1

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

Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76
  • 2
    Is there a reason why you need to do this using code in a web page? Have you considered exporting your email list to Outlook or ConstantContact? – aviemet Oct 26 '13 at 01:24
  • Do you have shell access? Replace sendmail with qmail and you can queue your sending. its worked for me in the same situation where I must regulate the number of messages sent in a time interval. And not to advertise, but Digital Ocean offers darn fine lampp hosting for $5 a month. – chiliNUT Oct 26 '13 at 01:44

2 Answers2

1

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.

Aaron Ratner
  • 111
  • 3
0

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

ssaltman
  • 3,623
  • 1
  • 18
  • 21
  • A code example please... – user2921945 Oct 26 '13 at 20:41
  • Ok, [http://en.wikipedia.org/wiki/Meta_refresh] '' – ssaltman Oct 27 '13 at 23:58
  • Within the head tag (this is in classic asp because that's what the site was written in - told you it was a long time ago) `"" then response.write request("wait") else response.write "600" end if select case request("wf") case "newsletter" %>;URL=http://www.mydomain.com//newsletter_autosend.asp?test=<%=request("test")%>&resend=<%=request("resend")%>&newsid=<%=request("newsid")%>">` – ssaltman Oct 28 '13 at 00:06
  • 1
    I have no idea why this question is off-topic or my solution is downvoted. This is a common coding problem - an entrepreneur with few resources needs a way to write code the fits within the constraints of his budget. I had the exact same problem building LandAndFarm.com. I was on a limited hosting service with a free business model and I found a solution that worked great. I sent a single email on a page and then waited and reloaded the page. The page was password protected so only I could access it. I really did send tens of thousands of newsletters this way for a while. – ssaltman Oct 28 '13 at 00:13