spertuit Posted June 1, 2013 Share Posted June 1, 2013 I have been working on an application where I need to send a zip file to my registered users. I'm not worried about speed to get the emails out, I just need to be sure I can send out the files to everyone. I am using phpmailer right now and it works for about 7 minutes, sends out 40 emails and than I get a 500 error and it quits, I am using an SMTP relay server my company uses and its not working out. Anyone have suggestions on a better way of getting this done? Here is a snippet of code: $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $phpMailer->SMTPKeepAlive = true; $mail->Host = "relay.appriver.com"; // SMTP server //$mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "relay.appriver.com"; // sets the SMTP server $mail->Port = 2525; // set the SMTP port for the GMAIL server $mail->Username = "username"; // SMTP account username $mail->Password = "password"; // SMTP account password $mail->From = "donotreply@domain.com" ; $mail->FromName = "ReEntry Website"; $mail->AddAddress("someone@domain.com"); $mail->WordWrap = 50; // set word wrap to 50 characters $mail->AddAttachment("../Placards/placards.zip"); // add attachments //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name $mail->IsHTML(true); // set email format to HTML $mail->Subject = 'ReEntry Request '; $mail->Body = "Parish Placards"; $mail->AltBody = "Parish Placards"; if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }else{ $stringData = "<p align=\"left\">Placards have been sent to " . $email . "</p>"; fwrite($fh, $stringData); } Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/ Share on other sites More sharing options...
boompa Posted June 1, 2013 Share Posted June 1, 2013 If you're sending the same thing to everyone -- with no personalization -- why not just add all the recipients to the BCC list of the email and send it just once? Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1433584 Share on other sites More sharing options...
jazzman1 Posted June 1, 2013 Share Posted June 1, 2013 Most of the shared hosting providers limit their maximum execution time of the scripts and set a rule of their SMTP relays about 1000 mails per day. So,if you have a lot of users you have to consider using the sleep php function and the cron job together avoiding flood the mail server. Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1433585 Share on other sites More sharing options...
Jessica Posted June 1, 2013 Share Posted June 1, 2013 Seems like it'd be easier to email a link so they can download them. Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1433586 Share on other sites More sharing options...
spertuit Posted June 3, 2013 Author Share Posted June 3, 2013 (edited) Sorry on a late reply. It's not the same email for everyone, it' based off the individuals name. As of right now I am emailing 300 people and getting a 500 error. This is a dedicated web server that is sending through a smtp relay. I thought that maybe its a limit, but we shouldn't be close to that with only about 310 total emails right now. If I cant get the emails, I may do a download link. I would much prefer the emails though. Edited June 3, 2013 by spertuit Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1433854 Share on other sites More sharing options...
kicken Posted June 3, 2013 Share Posted June 3, 2013 When it comes to mass mailing, what you should do is store the information you need to email into a DB, then have a background process do the emailing. That way the user doesn't have to sit and wait on a loading page for a long time while the emails go out. You can also disable timeouts on the background process so that it can run for as long as needed. Also, check your mailer library to see if it is reusing the same connection or opening a new connection to the server for every email it sends. One library I had used in the past did one connection per email. Changing it to reuse the same connection cut the run time nearly in half. Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1433864 Share on other sites More sharing options...
Solution spertuit Posted June 14, 2013 Author Solution Share Posted June 14, 2013 I changed smtp relay to a true exchange account and now everything is fine. Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1436065 Share on other sites More sharing options...
Pawan_Agarwal Posted June 15, 2013 Share Posted June 15, 2013 Can I use the same code to send email from my gmail account ??? Quote Link to comment https://forums.phpfreaks.com/topic/278673-php-application-sending-out-many-emails/#findComment-1436115 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.