Sending an email to over 100k email addresses?

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

User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Sending an email to over 100k email addresses?

Post by phice »

How would I go about sending out an email to over 100,000 email addresses? I've heard that mail() isn't too reliable and I should use SMTP or the like?

What would be the best way to go about this?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You might want to use a service. Try Googling "bulk email service". I have clients that have had a good experience with Constant Contact, but there are many others.
(#10850)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I'd prefer to do it locally (free) if at all possible.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The basics are set up a cron to run a batching file that sends 10 or 100 at a time through your SMTP server using a class such as phpMailer.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

For free you can also use phpList.
(#10850)
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

might need a sleep function

Post by dibyendrah »

sending the mail over 10,000 at once will make the SMTP go mad.. So, what we can do is put the sleep(1) after each mail() function will keep the SMTP cool.
I'm not confident to say that but this is just my point of view.
:lol:

Cheers,
Dibyendra
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

phpMailer can handle bulk emailing yes.... the basic principle, if you want to do it yourself, is to use fsockopen() to establish a connection with the server. Then you loop over all your email addresses sending out the appropriate SMTP commands (via fwrite()) to deliver the email.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Re: Sending an email to over 100k email addresses?

Post by AKA Panama Jack »

phice wrote:How would I go about sending out an email to over 100,000 email addresses? I've heard that mail() isn't too reliable and I should use SMTP or the like?

What would be the best way to go about this?
Ew... 100k email spam?

You really don't want to use the mail() for something like that. Mail() will usually WAIT for a response indicating if the mail was sent to the address or not. Depending upon the server and connection you might be lucky to send an email every second. :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Sending an email to over 100k email addresses?

Post by Chris Corbyn »

AKA Panama Jack wrote:
phice wrote:How would I go about sending out an email to over 100,000 email addresses? I've heard that mail() isn't too reliable and I should use SMTP or the like?

What would be the best way to go about this?
Ew... 100k email spam?

You really don't want to use the mail() for something like that. Mail() will usually WAIT for a response indicating if the mail was sent to the address or not. Depending upon the server and connection you might be lucky to send an email every second. :)
It's not just that... mail() opens a new connection to the server for each and every email it sends... this is slow. If you can use a single connection to send any number of emails things will be much faster. You can just say HELO/EHLO once, then repeatedly go "mail from:", "rcpt to", "data". I can't remember why but emails sent via mail() are often rejected as spam too... though this would usually be down to the content of the email (including the headers).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Sending an email to over 100k email addresses?

Post by John Cartwright »

phice wrote:How would I go about sending out an email to over 100,000 email addresses? I've heard that mail() isn't too reliable and I should use SMTP or the like?

What would be the best way to go about this?
I was just about to post this topic. Wee.. 8)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Sending an email to over 100k email addresses?

Post by onion2k »

AKA Panama Jack wrote:Ew... 100k email spam?
Just because it's a big list doesn't immediately mean it's spam. I've used to have a client with over 250k addresses.. I used Perl and a batching system to do each send. The latest version of my code can do a sustainable 10 emails customised with individual names and stuff per second.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Re: Sending an email to over 100k email addresses?

Post by phice »

AKA Panama Jack wrote:Ew... 100k email spam?
Just because I have a popular site that has an excessive amount of email addresses signed up doesn't mean it's spam. :)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

d11wtq wrote:phpMailer can handle bulk emailing yes.... the basic principle, if you want to do it yourself, is to use fsockopen() to establish a connection with the server. Then you loop over all your email addresses sending out the appropriate SMTP commands (via fwrite()) to deliver the email.
Could you point me in the direction of what to use for the fsockopen or even an example script? Too bad EvilWalrus isn't still around.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

phice wrote:
d11wtq wrote:phpMailer can handle bulk emailing yes.... the basic principle, if you want to do it yourself, is to use fsockopen() to establish a connection with the server. Then you loop over all your email addresses sending out the appropriate SMTP commands (via fwrite()) to deliver the email.
Could you point me in the direction of what to use for the fsockopen or even an example script? Too bad EvilWalrus isn't still around.
It just so happens I'm in the process of developing one and discussing stuff in Theory & Design :P

viewtopic.php?p=259919#259919

You can maybe even try just using the code as it is if you wanted but I warn you that it's not fully tested (and it's PHP5). It would be easy enough to change to PHP4.

To send a batch email you'd do:

Code: Select all

$addresses = array(
    'one@domain.com',
    'two@domain.com',
    'three@domain.com'
);

$mailer = new mailer(new SMTPConnection('smtp.your-isp.com'), 'yourdomain.com');

$mailer->addPart('<strong>some html</strong>', 'text/html');
$mailer->addPart('some plain text');
$mailer->send($addresses, 'your@address.com', 'The subject');
$mailer->close();
If you're just looking for the logic then look at the methods:

SMTPConnection::connect()
mailer::command()
mailer::getResponse()
mailer::buildMail()

Cheers :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I can't remember why but emails sent via mail() are often rejected as spam too... though this would usually be down to the content of the email (including the headers).
Figures.
Just because I have a popular site that has an excessive amount of email addresses signed up doesn't mean it's spam
Can I see your site?

Code: Select all

$addresses = array(
    'one@domain.com',
    'two@domain.com',
    'three@domain.com'
);

$mailer = new mailer(new SMTPConnection('smtp.your-isp.com'), 'yourdomain.com');

$mailer->addPart('<strong>some html</strong>', 'text/html');
$mailer->addPart('some plain text');
$mailer->send($addresses, 'your@address.com', 'The subject');
$mailer->close();
Well it certainly looks nice, d11wtq
Post Reply