pascal_22 Posted July 4, 2012 Share Posted July 4, 2012 Hello, I have over 10 000 users in my DB who want receive newsletter from me. Until now, i use SELECT Email,Username...... from my table and i loop each row with a mail() function to send a mail to this user. Someone told me that i should only select 100 users and send email to them, after 5-10 minutes select another 100 user and so on... Is that a good idea? Why my first way wasn't good? Thanks a lot! Pascal Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/ Share on other sites More sharing options...
Isset1988 Posted July 4, 2012 Share Posted July 4, 2012 If your server is shared, maybe you have a send mail limit. If your server is dedicated, you can send unlimited mails, but you must be sure that users who get the emails dont send your mail to spam. If many users, send your newsletter to a spam folder, maybe your dedicated server/ip blacklisted. The guy who told you that you must send 100mails per 5 minutes, maybe has his script in a shared server. Mail function is an easy way to send mails (usually used on contact forms). Try search on google for a tutorial how to send newsletters. Maybe this tutorial help you! http://net.tutsplus.com/articles/news/build-a-newsletter-system-with-php-and-mysql-new-plus-tut/ Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359191 Share on other sites More sharing options...
Pikachu2000 Posted July 4, 2012 Share Posted July 4, 2012 It says right in the PHP manual that mail() is not suitable for sending large volumes of email in a loop. Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359197 Share on other sites More sharing options...
pascal_22 Posted July 5, 2012 Author Share Posted July 5, 2012 Good Thanks for all! I appreciate. I still have a question: I know now how to create a cron job, I understand that my script should select 100 rows and send one email per row in a loop But what i don't understand is how to figure the script that will select another 100 rows, and sent email to each row and so on, and when all members receive my newsletter, how i would stop de cron job.... for now, i have over 10 000 emails to send weekly, i hope in a near future, sending over 100 000 or more weekly... How i settup a cron job that will call my script every 10 minutes 'till all my newsletter was send...? Thanks a lot! Pascal Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359222 Share on other sites More sharing options...
Isset1988 Posted July 5, 2012 Share Posted July 5, 2012 Maybe these "how to" on youtube help you. 1 - http://www.youtube.com/watch?v=NZ73k_KPEuo 2 - http://www.youtube.com/watch?v=tlqmbNtW_x8 3 - http://www.youtube.com/watch?v=g4LxF5sVgPE 4 - http://www.youtube.com/watch?v=hDKCb5o-SHg 5 - http://www.youtube.com/watch?v=zeT2RpGbiug 6 - http://www.youtube.com/watch?v=ZM2uxb8gfn4 Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359477 Share on other sites More sharing options...
downah Posted July 5, 2012 Share Posted July 5, 2012 You might wanne look at my thread : http://forums.phpfreaks.com/index.php?topic=362077.0 and here http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359503 Share on other sites More sharing options...
redarrow Posted July 6, 2012 Share Posted July 6, 2012 a hidden solution using a 3rd part application and php exec http://www.scriptftp.com/reference.php?go=topic123 once you master this send million's daily. Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359576 Share on other sites More sharing options...
pascal_22 Posted July 6, 2012 Author Share Posted July 6, 2012 Ok thanks!! I'll check it out!! Thanks!! Pascal Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359650 Share on other sites More sharing options...
downah Posted July 6, 2012 Share Posted July 6, 2012 I just got my script working.. I'll post it here: <?php // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/mail/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/mail/lib/MailClass.inc'); //set execution time limit to 5 minutes $safeMode = ( @ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1 ) ? TRUE : FALSE; if ( $safeMode === FALSE ) { set_time_limit(300); // Sets maximum execution time to 5 minutes (300 seconds) // ini_set("max_execution_time", "300"); // this does the same as "set_time_limit(300)" } echo "max_execution_time " . ini_get('max_execution_time') . "<br>"; //db connection $con = mysql_connect("xx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xx", $con); // Setup body $textBody = "Dear {MEMBER_NAME},\n\nCheck out PHP Freaks: http://www.phpfreaks.com\n\nSincerely,\nAdmin"; $htmlBody = "Dear {MEMBER_NAME},<br /><br />Check out PHP Freaks: http://www.phpfreaks.com<br /><br />Sincerely,<br />Admin"; // instantiate the class $mailer = new FreakMailer(); // Get the user's Email $sql = mysql_query("SELECT displayname,email FROM engine4_users2")or die(mysql_error()); //lets reset the time limit of the server everytime an email is sent to bypass maximum while (1==1) { set_time_limit(30); // sets (or resets) maximum execution time to 30 seconds) // .... put code to process in here while($row = mysql_fetch_object($sql)) { // Send the emails in this loop. $member_name = $row->displayname; $mailer->AddAddress($row->email); $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, $htmlBody); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{MEMBER_NAME}', $member_name, $textBody); $mailer->Send(); $mailer->ClearAddresses(); $mailer->ClearAttachments(); $mailer->IsHTML(false); echo "Mail sent to: " . $member_name . "<br />"; } usleep(1000000); // sleep for 1 million micro seconds - will not work with Windows servers / PHP4 // sleep(1); // sleep for 1 seconds (use with Windows servers / PHP4 if (1!=1) { break; } } ?> Just change the query, and follow the tutorial in my thread and you'll get it If not let me know and I'll help you! Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1359652 Share on other sites More sharing options...
pascal_22 Posted July 16, 2012 Author Share Posted July 16, 2012 thanks to all for your good help!! i appreciate! Have a good day! Pascal Quote Link to comment https://forums.phpfreaks.com/topic/265213-php-script-to-send-a-lot-of-mail-to-user/#findComment-1361958 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.