Jump to content

PHP application sending out many emails


spertuit
Go to solution Solved by spertuit,

Recommended Posts

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);
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by spertuit
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.