Page 1 of 1

Mass Email?

Posted: Mon Dec 08, 2003 5:43 pm
by Mr. Tech
Hi guys!

I have a subscriber list and use software that cost me $100s of dollars and takes quite a while(Maybe an hour) to send out just 1,000 emails!

Does anyone know of any code that will allow me to send out something like 30,000 emails per hour?

I have this code but I don't think it works...:

Code: Select all

<?php
function send_mail($to,$subject,$mail_body) 
{
global $youremail
$Scharset = "iso-8859-1";
$subject = stripslashes($subject);
$mailbody = stripslashes($mail_body) . "\n\n";
$mailheaders .= "Content-Type: text/plain; charset=$Scharset\n";
$mailheaders .= "From: $youremail<$youremail>\n";
$mailheaders .= "Reply-To: $youremail\n";
$mailheaders .= "X-Mailer: $youremail";
@mail($to,$subject,$mailbody,$mailheaders);
} 

$sendemail = "select * from "maillist";
$showresult = mysql_query($sendemail) or die("<b>MySQL Error:</b> " . mysql_error());
$numrows = mysql_num_rows($showresult);
if ($numrows==0) print "No email addresses found!";
for ($i=0; $i<100; $i++) { 
echo ("    ");  flush();
}
for($x=0;$x<$numrows;$x++) {
	unset($name, $email);
	$row = mysql_fetch_array($showresult);

	send_mail($row[email],$subject,$message);

	flush(); 
	usleep(5000);
	}

?>
Will that work?

Thanks

Ben

Posted: Mon Dec 08, 2003 6:08 pm
by m3mn0n
If you have a Windows server, no.
The usleep() function delays program execution for the given number of micro_seconds. A microsecond is one millionth of a second.

Note: This function does not work on Windows systems.

Posted: Mon Dec 08, 2003 8:38 pm
by Mr. Tech
But on a normal server (something like http://www.lunarpages.com) it would send out the emails really fast? That's all I need to know.

Thanks.

Posted: Thu Dec 11, 2003 2:17 am
by m3mn0n
30,000/mails an hour is pretty damn quick. I was just doing a benchmark test to see how much quicker my local server is with the Zend Optimizer, and a short script I made printed out this as a result:
Done loading into the DB & sending the 50 emails to yourself...

...Execution time: 37.72928 seconds
Now after doing the math, 30000 emails would take my local server 6 hours to do. Yes, it isn't a top of the line P4, but I think it will be pretty tough to cut that time by 6. Who knows though, I could be wrong. :wink:

btw the db connection part took 1.5 seconds, and the mailing took the rest. (i did seperate tests to see which one hogged the most time)

Posted: Thu Dec 11, 2003 3:05 am
by JayBird
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... not very efficient.

To send email using sockets, I suggest reading this:
http://cr.yp.to/smtp.html
and taking a look at the functions used here:
http://www.ima.pl/blizbor/smtp.phps

sendmail to 5000 recipiƫnts

Posted: Thu Mar 11, 2004 6:16 am
by Frantic Cruiser
Bech100 wrote: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... not very efficient.

To send email using sockets, I suggest reading this:
http://cr.yp.to/smtp.html
and taking a look at the functions used here:
http://www.ima.pl/blizbor/smtp.phps
That last link doesn't work :(

My problem :
I'm in a small company and i have to do a mailing to 5000 recipiƫnts. I wondered if i could do this with sendmail in a loop ... But you think it's a bad idea, i figured indeed it would be quit a traffic jam on the network with all those connections.

Do you suggest an alternative?

thx

Frantic

Posted: Thu Mar 11, 2004 6:24 am
by m3mn0n
Oh the links went dead, eh? Bummer.

Try this search for refresh links and good resourceful information:

Google search for: [google]sending emails php sockets [/google]