lip9000 Posted January 29, 2009 Share Posted January 29, 2009 Hi, I have a mailing script on my website that sends an email to every user in the database, as the site has 30,000 members now everytime I do a mass mail the server freezes and I have to get hosting support to reboot it for me as the mysql and mail server gets thrashed. And it's on a dedicated dual xeon! So I've decided that to take the stress off having to query the database to get every user, I am downloading the emails column from my database into a txt file and each email will be on a new line. What would I need to modify in this script to make it go through each email in the text and send mail to it instead of grabbing it from the DB? Also if you have any tips as to how I could take some stress off the mail server that would be fantastic! Thanks a million! //FORM ACTION if (!empty($_POST['mm_esubj'])&& !empty($_POST['mm_cont']) && (isset($_POST['mm_subact'])&&($_POST['mm_subact']=='1'))) { set_time_limit(0); $query="SELECT COUNT(*) as Num FROM lol_users WHERE (validated=1)".($_POST['mm_forced']=='1'?'':' AND (orecvmail=1)'); $qres=mysql_query($query) or draw_error('MYSQL ERROR: '.mysql_error()); $ucount=mysql_fetch_array($qres);$ucount=(int)$ucount['Num']; $query="SELECT email FROM lol_users WHERE (validated=1)".($_POST['mm_forced']=='1'?'':' AND (orecvmail=1)'); $qres=mysql_query($query) or draw_error('MYSQL ERROR: '.mysql_error()); if (isset($_POST['mm_plain'])&&($_POST['mm_plain']==1)) { $conttype='text/plain'; $emailcont=$_POST['mm_subj']."\n\n".$_POST['mm_cont']; } else { $conttype='text/html'; $emailcont=file_get_contents('inc/tpl/massmail.htm'); $emailcont=str_replace('{TITLE}',$_POST['mm_subj'],$emailcont); $emailcont=str_replace('{SITEADDR}',SITEADDR,$emailcont); $emailcont=str_replace('{SUBJECT}',$_POST['mm_subj'],$emailcont); $emailcont=str_replace('{CONTENT}',nl2br($_POST['mm_cont']),$emailcont); } $i=1;echo 'Sending mail...'; while (($userinfo=mysql_fetch_array($qres))&&($i<=$ucount)) { site_mail($userinfo['email'],$_POST['mm_esubj'],$emailcont); echo ' '; if ($i%20==0) {echo $i.'..';} ob_flush();flush();$i++; } } Infact my server froze after finishing downloading the list of emails! I rebooted but. Link to comment https://forums.phpfreaks.com/topic/142931-doing-a-mass-mail-with-emails-from-a-text-document/ Share on other sites More sharing options...
printf Posted January 29, 2009 Share Posted January 29, 2009 Use a mail envelope and you will avoid wasting resources. All mail servers support envelopes, mail servers are designed that way so people don't make thousand's of connections for no reason at all. Use a socket class that can directly connect to the mail server, send your Mail From and (Mail To, Mail Bcc, Mail Cc envelope) and your message and the mail server will handle the sending of the message to all addresses in the envelope. All that is done using (1) connection. Link to comment https://forums.phpfreaks.com/topic/142931-doing-a-mass-mail-with-emails-from-a-text-document/#findComment-749518 Share on other sites More sharing options...
lip9000 Posted January 29, 2009 Author Share Posted January 29, 2009 Use a mail envelope and you will avoid wasting resources. All mail servers support envelopes, mail servers are designed that way so people don't make thousand's of connections for no reason at all. Use a socket class that can directly connect to the mail server, send your Mail From and (Mail To, Mail Bcc, Mail Cc envelope) and your message and the mail server will handle the sending of the message to all addresses in the envelope. All that is done using (1) connection. It currently is using the php mail envelope function, the function site_mail($userinfo['email'],$_POST['mm_esubj'],$emailcont); is a made up function that is included earlier in the file that contains the bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] ). I think the problem was only the sql database from gathering all the emails, but now that I have them in a text document, how can I parse through the txt file to send the message to each email that is on a new line? Link to comment https://forums.phpfreaks.com/topic/142931-doing-a-mass-mail-with-emails-from-a-text-document/#findComment-749575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.