tags:

views:

206

answers:

3

I've got 80,000 users on my site and i've recently turned away from the forum script i've been using and built something very simple myself that works just as well (the forum script was too bloated and resource intensive for my simple site)

The only thing i've lost is the ability to mass email all my members.

So i'm looking to come up with a script to do it myself. After looking around (including questions on here) I decided using Swift Mailer would be a good idea.

However i've been through all the documentation and can't see how to send say "100 at a time" and i'm not sure how to go about it.

To put it simply. I have an admin panel with a form with two inputs "subject" and "message". When I click submit what is the safest way for me to send 80,000 emails without crashing my server or being marked as spam?

I'm on quite a beefy dedicated server so don't have the problems associated with shared servers.

Thanks in advance for any advice!

+1  A: 

Safe option is to send emails one after another. I usually send no more than 10 e-mails evey 10 minutes. Simple script fired by cron is all you need.

Sending many emails at once is one thing but have them all delivered and passed by servers filters is diffrent thing...

smentek
I realise a cron job is a good way to do it. But I don't want to necessarily do it at 3pm every day. I want to be able to go into the backend, write the email and click send. Is there a way to create a one off cron job in php? (although I think that doesn't fit under the term "cron job")
Rob
Cron can be used in many ways. You may for example have a simple model (one table in databse) called: emailsToSend (kind of simple buffer). Fields in database for model like: id, email_id, created_at, sent. Every record in emailsToSend is an event: "sending an e-mail'. You set cron to fire your script every 5 minutes. Script:1. checks if there are any records (e-mails to send). 2. Takes last 10 or them (by date of creation), 3. Send them and mark tham as send (simple boolean flag for this)4. Ends.Script is fired by cron, so you will not have to do it from browswer...
smentek
A: 

A class like Swiftmailer has options to do mass email.

Frank Heikens
Like I said i'm already using Swift Mailer. However, from what I can tell if I add 80,000 people via bcc it's just going to loop through that 80,000 people. I don't really want to leave my browser open while it does that. It will also probably cause a server timeout.So I need another way of doing so. If Swift Mailer is able to do this I haven't been able to find it in the documentation.
Rob
A: 

Here's my idea... Assuming you are hosted on a linux type box. This is of course at the bare minimum without knowing your code. Create a file on the server called sendmails.php

<? 
loop through email addresses however you do it
{
 usleep(250000); // sleep for quarter of a second 
 mail('[email protected]', 'My Subject', 'message');
}
?>

Save it, then in another file startemails.php you can open in your browser

<?
system("&php sendmails.php");
?>

Even if the server times out, the system call should still complete its work. 80,000 emails should send over about 6 hours using this method. Change the time in usleep to take more or less time.

SethCoder
You could also modify it to send X amount of emails then wait X amount of time before doing the next batch.
SethCoder