.Darkman Posted February 25, 2008 Share Posted February 25, 2008 Hello, I have a database of over 2000 users. I wish to send newsletters to them via PHP's mail() function. What is the best way to do ? I'm asking this because, i read somewhere that using the mail() for a large number of users can crash the server. So, whats the best way to do it ? I'm on Shared hosting. Thanks, Shrihari.S Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 25, 2008 Share Posted February 25, 2008 i would suggest looking at the PEAR Mail package, i believe its more 'Reliable'. i dont know anything about it though i wish i could be more help, try this link: http://pear.php.net/package/Mail hope this helps, Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 25, 2008 Share Posted February 25, 2008 best move is to batch action it into 100-200 emails at a time Quote Link to comment Share on other sites More sharing options...
.Darkman Posted February 25, 2008 Author Share Posted February 25, 2008 i would suggest looking at the PEAR Mail package, i believe its more 'Reliable'. i dont know anything about it though i wish i could be more help, try this link: http://pear.php.net/package/Mail hope this helps, I'll take a look... thx best move is to batch action it into 100-200 emails at a time How do i do that ? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 25, 2008 Share Posted February 25, 2008 you write a script to send X emails a time and rerun it every so often. At 2000 emails in 1 script you will probably get some nasty emails from your hosting company as they will call you a spammer. Have to spread it around Quote Link to comment Share on other sites More sharing options...
.Darkman Posted February 26, 2008 Author Share Posted February 26, 2008 Actually, php.net/mail says that it is better to use PEAR package for large volume of mailing. So, is the following code good ? Or, does this also put a lot of stress on the server ? <?php include ('/home/username/php/Mail.php'); $mail = Mail::factory("mail"); $headers = array("From"=>"me@mydomain.com", "Subject"=>"Test Mail"); $body = "This is a test!"; foreach($emails AS $email) { // about 2500 email addresses $mail->send($email, $headers, $body); } ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 26, 2008 Share Posted February 26, 2008 personally ive never used pear but i can give u a tip. time the script AND each email using microtime(). This will tell you roughly how much time it takes to complete the operations. during that time look at your processor usage and memory usage. while the script is running try to run another one along-side etc, there are numerous ways to stress test a script. the script looks good to me. have you tried it are there any errors? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 26, 2008 Share Posted February 26, 2008 personally ive never used pear but i can give u a tip. time the script AND each email using microtime(). This will tell you roughly how much time it takes to complete the operations. during that time look at your processor usage and memory usage. while the script is running try to run another one along-side etc, there are numerous ways to stress test a script. the script looks good to me. have you tried it are there any errors? Run time/memory usage aren't the concerns here its being labeled a spammer that will happen if you are found to send 2000 emails in less than a minute you have to spread it out over hours unless you have a security certificate or are on some sort of white list. Quote Link to comment Share on other sites More sharing options...
freenity Posted February 26, 2008 Share Posted February 26, 2008 You could insert a sleep(10) in the while sending loop, so the server is not so loaded, but you also will need to set the script execution time to 0, so it doesn't get closed automatically. To send mail check this code: http://gwphp.feudal-times.net/?p=4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.