You could change the TO: to something generic like "Email List Subscriber" then add everyone to the BCC field and then generate 1 email with 9000 people in the BCC field. Let sendmail do the rest. It should take less time to send the emails and only a few seconds to generate your page. Cheers Jason -----Original Message----- From: Chris Payne [mailto:cjp@planetoxygene.com] Sent: Wednesday, March 12, 2003 11:41 AM To: php-db@lists.php.net Subject: newsletter optimization help needed Hi there Everyone, Below is some code I use to send a newsletter to clients subscribed on my mailing list. The problem is I have over 9000+ email addresses in the DB and it takes around 30-45 minutes to send them with the below code. Can anyone see someway I can optimize it so it sends out the newsletter any faster? I've probably gone about this system the long way, but it works - I just need to find a way to make it faster :-( Thanks everyone All the best Chris --- <? $connection = mysql_connect("localhost","Username","Password") or die("Couldn't make a connection."); $db = mysql_select_db("WhateverDB", $connection) or die("Couldn't select database."); $sql = "SELECT * FROM emailtest"; $sql_result = mysql_query($sql,$connection) or die("Couldn't execute query."); while ($row = mysql_fetch_array($sql_result)) { $emailadd = $row["EMail"]; $emailname = $row["emailname"]; $emailphone = $row["emailphone"]; $emailaddress = $row["emailaddress"]; $MP = "sendmail -t"; $HT = "<html><body>"; $HT = "</body></html>"; $subject = "$subject"; $NOTE = "$emailtests"; $NOTE = str_replace("*email*", "$emailadd", $NOTE); $NOTE = str_replace("*name*", "$emailname", $NOTE); $NOTE = str_replace("*phone*", "$emailphone", $NOTE); $NOTE = str_replace("*address*", "$emailaddress", $NOTE); $TO = "$emailadd"; $fd = popen($MP,"w"); fputs($fd,"MIME-Version: 1.0\r\n"); fputs($fd,"Content-type: text/html; charset=iso-8859-1\r\n"); fputs($fd, "To: $TO\n"); fputs($fd, "From: sales@me.com\n"); fputs($fd, "Subject: $subject\n"); fputs($fd, "X-Mailer: PHP3\n"); fputs($fd, "Email: $email\n"); fputs($fd, "$HT"); fputs($fd, "$NOTE"); fputs($fd, "$EHT"); } pclose($fd); exit; mysql_free_result($sql_result); mysql_close($connection); ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php