Sending mass emails

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
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Sending mass emails

Post by vnwebworld »

Hi all,

I am doing a project for a client, and he has many customers. What he wants is sending to an email list, up to 1 million emails.

I have tried to loop and sent emails but the browser gets timeout. Do you guys have any solution?

I need this quite urgent. Please help me!

Thanks and regards.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Use the PEAR mail functions or PHPMailer.

Make sure you're using SMTP too.
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Post by vnwebworld »

Thanks for fast reply.

I have tried PHPMailer and I am not sure how it can send like 1 million emails. Do you have a sample code?

And one problem with PHPMailer is emails will go to bulk box like AOL or Hotmail. My current solution is relaying through GMail, and PHPMailer cannot support it. Any suggestions?

Thanks for viewing.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

vnwebworld wrote:Thanks for fast reply.

I have tried PHPMailer and I am not sure how it can send like 1 million emails. Do you have a sample code?

And one problem with PHPMailer is emails will go to bulk box like AOL or Hotmail. My current solution is relaying through GMail, and PHPMailer cannot support it. Any suggestions?

Thanks for viewing.
Whoaaa... don't try sending 1,000,000 emails in one go from one script unless you hate your SMTP server administrator or you've not had your weetabix this morning 8O

Do them in batches of 100 or so every minute.... much easier.
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Post by vnwebworld »

Any suggestions for separating? The problem is my client gives me a list of emails like this

email1
email2
...

up to 1 million emails. And I think the time for separating them is also much, and no place to save temporary list also.

Any suggestions ?

Thanks a lot.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

just have PHP read the file with the emails in it, explode on line breaks so that they are in an array.

then do a foreach on it, put a counter in the loop and every time it hits a multiple of 100 have PHP sleep for 120 seconds.

it will probably take about half a day to do it all (someone divide a million by 100, times it by 120 and divide it by 60 please, so we know the minutes :P), and i doubt your server admin would like you very much if your on a shared host.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmm... I'd actually pull the emails out of the flat file into a database.

I'd then use CRON to run a the mail sending script once a minute and record the addresses that have had emails sent out in the database. You can just have a field called "sent" or suchlike.
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Post by vnwebworld »

To Feyd: Thanks Feyd, I already take a look at these. I did search the forum before I post this topics.

To jayshields: actually I did not send out email using my hosting smtp. I use GMail to send out. But the time is so much :(

To d11wtq: Thanks man, I also think of this solution but the problem is 1 million email, and 1 minute I send out only 1 email, so I need 1 milliion minutes for 1 category :(.

By the way, how many emails can I add to the BCC field ? I thought of a solution that using cron to send email, each time about 200 or more depending on how many I could add to BCC field.

Any suggestions ?

Thanks all for viewing and giving your suggestions.
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Post by vnwebworld »

And one more thing is like this forum, if administrator want to send announcements to members through emails, what does it do ? Since I think a good forum like this can get 100000 members.

Any idea ?

Thanks for viewing
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

vnwebworld wrote:And one more thing is like this forum, if administrator want to send announcements to members through emails, what does it do ?
Simple: They don't.

There is a purpose for email - to communicate with someone. There is no practical reason for communicating with a *million* people except commercial use or spam.

If its commercial use, you shouldn't be relying on *gmail*, a free provider to send the emails. If its spam, we have no desire to help.

Worse, we've answered every part of your question. Use phpmailer, read the docs, and you can indeed send *massive* numbers of emails. You can even spread it across multiple smtp servers, speeding up the process. phpmailer also offers the ability to do email batching, yet further speeding it up.

PHPMailer can in fact send with gmail as the smtp server. The "it goes to bulk box" is because you are spoofing the smtp server (you aren't gmail!), and sending BULK EMAIL!
vnwebworld
Forum Newbie
Posts: 9
Joined: Thu Mar 09, 2006 8:07 am

Post by vnwebworld »

Roja wrote:
vnwebworld wrote:And one more thing is like this forum, if administrator want to send announcements to members through emails, what does it do ?
Simple: They don't.

There is a purpose for email - to communicate with someone. There is no practical reason for communicating with a *million* people except commercial use or spam.

If its commercial use, you shouldn't be relying on *gmail*, a free provider to send the emails. If its spam, we have no desire to help.

Worse, we've answered every part of your question. Use phpmailer, read the docs, and you can indeed send *massive* numbers of emails. You can even spread it across multiple smtp servers, speeding up the process. phpmailer also offers the ability to do email batching, yet further speeding it up.

PHPMailer can in fact send with gmail as the smtp server. The "it goes to bulk box" is because you are spoofing the smtp server (you aren't gmail!), and sending BULK EMAIL!
Thanks for your reply.

My client and I not going to use this program to spam. The reason why I use Gmail because my client wants me to give him many options. The first option is he will buy a good hosting for sending email and second one is using free smtp server. I also give him notice about not relying on gmail. As a service provider, I just find all solutions and give to my client :)

I will try PHPMailer again, maybe I havent taken a look at it carefully.

Thanks again for your comments.
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

I send mine in batches of 50 and use sleep(3) to stop timeout
eXpertPHP
Forum Newbie
Posts: 5
Joined: Sun Mar 12, 2006 9:11 am
Contact:

Post by eXpertPHP »

You can send 1 milion (or more) of e-mails with XPertMailer very easy. Use for this Bcc, send them a package of 1000 (or less) e-mails to prevent the blocking mode. If you want to send via a Relay SMTP server like Gmail (from trusted host), then i will show you a simple example 'howto':

Code: Select all

<?php

set_time_limit(0);
error_reporting(E_ALL);

// path to XPertMailer.php file 
require_once 'XPertMailer.php';

$mail = new XPertMailer(SMTP_RELAY, 'smtp.gmail.com');

$mail->auth('username@gmail.com', 'password', AUTH_DETECT, SSL_TRUE, 465);
$mail->from('username@gmail.com', 'My Name');

// many e-mail addresses separated by comma and space ...
$header['Bcc'] = 'client1@host1.com, client2@host2.com, client3@host3.com';
$mail->headers($header);

$send = $mail->send('destination@hostname.com', 'subject', 'text/plain message');

echo $send ? "Done." : "Error.";
echo "\nServer response: ".$mail->response;

?>
Execute the script (for preventing timeout on browser) from command line like: php -f /path/script.php
Make sure you have OpenSSL module (extension) enable on your PHP configuration.
Notice: put the real 'From' e-mail address that is the Gmail user account.
Post Reply