Mass email 1,000 - 1,000,000 users?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Mass email 1,000 - 1,000,000 users?

Post by psychotomus »

I need a good/fast way to mail this many users.

Currently i have code something like this

$headers = "From: MehSite.Com <my email>\n\r";

loop trhough users in DB
mail($email, $subject, $message, $headers);
end loop

this just takes to long. to even mail 30,000 users it takes like 3hours or so. lols.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Mass email 1,000 - 1,000,000 users?

Post by Weiry »

Your problem is not a code efficiency problem.
If you want to make it run faster, buy a faster computer.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Mass email 1,000 - 1,000,000 users?

Post by Eric! »

Don't encourage the spammers. lol
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: Mass email 1,000 - 1,000,000 users?

Post by anand »

your code is perfectly fine. I don't think of any other way. upgradeing your server might help.

what's your server configuration? is that a dedicated or shared server?
SpartanDonut
Forum Newbie
Posts: 1
Joined: Mon Oct 26, 2009 10:55 am

Re: Mass email 1,000 - 1,000,000 users?

Post by SpartanDonut »

Another thing to look into possibly is how optimized your database / query is. There might be a more efficient way to grab the email addresses than what you are doing.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Mass email 1,000 - 1,000,000 users?

Post by Eran »

Using the mail() function directly will not scale with a large volume of Emails. Read the second note in the manual - http://php.net/manual/en/function.mail.php:
Note: It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.
In addition to the packages they mention there, you can also try Zend_Mail and swiftmailer.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Mass email 1,000 - 1,000,000 users?

Post by Eric! »

Evil! Evil I tell you!
Post Reply