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
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Dec 08, 2003 5:43 pm
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
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Mon Dec 08, 2003 6:08 pm
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 .
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Dec 08, 2003 8:38 pm
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.
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Thu Dec 11, 2003 2:17 am
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.
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)
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Thu Dec 11, 2003 3:05 am
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
Frantic Cruiser
Forum Newbie
Posts: 1 Joined: Thu Mar 11, 2004 6:16 am
Post
by Frantic Cruiser » Thu Mar 11, 2004 6:16 am
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
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Thu Mar 11, 2004 6:24 am
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]