Jump to content

Recommended Posts

I'm using PHPMailer to send a number of emails.  I get the result of a query on email addresses and then go through a loop to send each email.  I cannot send them as a group since I don't want all recipients to see everyone's email address.

 

I'm using a test group of 100 records.  One time, it will get all the way through.  The next time, it will send 18.  The next time, 77.  So, I can't count on this.  I've put a delay in with usleep() after so many records, but I will have much larger volumes and I'm trying to not delay the sending too much.  Can anyone shed any light on why there are inconsistent send counts, especially since they vary so widely on a small batch?  If I can understand the factors that cause it to fail, maybe I can control them better.

 

I'm sending them through my Comcast account for the meantime as a test.  I'm sure a dedicated server would perform better, but it is important to understand what affects this since I'll have much larger volumes on the dedicated server.  I would think that this small amount through the Comcast server shouldn't pose a problem.

 

Thanks for any suggestions.

You maybe overloading the mail server. If PHPMailer is using the mail() function to send large volumes of email then this is bad as the server needs to open and close SMTP sockets each time it is called. For this reason it is best to use PEAR mail for large volumes.

Using usleep() is time in microseconds which is not a great deal of time to pause. Maybe try sleep(2) which will sleep for 2 seconds each iteration.

adamsargant - I downloaded, installed and tried Swiftmailer.  I tried using the batch sending function to avoid a ton of looping.  It seemed to work a bit better, but I was still having some failure before hitting 100 emails.  Maybe it is how I've constructed my logic.  Could you briefly explain what method you use to send out email batches?

 

neil.johnson - I have used sleep() with this.  I was using usleep(1500000) to optimize my ability to send vs. the time it takes.  On the other item, are you saying that if I use the PEAR classes that I wouldn't have a bunch of opens/closes for SMTP?  I did some reading on PEAR, but it looks like it still uses the underlying mail function in PHP, so wouldn't that operate in the same way?  Might it be possible to use the PEAR classes with something like Swiftmailer that has a batch sending capability?  I'm not meaning to ask for a detailed explanation of how PEAR works, I'm just trying to get some insight into whether it will be worth investing time in researching/learning it (particularly because it looks like there is more to it on their web site).

 

Thanks...

I send out a monthly email for a client to in excess of 15000 recipients... because of the way in which my client sends their emails, each one does have to be prepared individually (well, I could send them out in maybe 36 batches, but I don't :-), I use sleep(1) between each $mail->send().

 

The good thing about swiftmailer is the active forum where you can get assistance with this sort of thing :-)

  • 10 months later...

I know this is an old topic but I found it researching the same issue... I too am using PHPMailer and getting errors when sending multiple emails (only about 5 or 6 or so). I have tried the sleep() that was suggested in this post but to no avail.

 

I just registered on this site to be able to post and ask about this... I hope it's ok that I didn't start a new topic.

 

I seem to have a handle on it when I send one email but if I try to send multiple emails I get all kind of errors (an authentication error, a 550 relay error and a sender already given error):

 

Webmasters have NOT been notified of your new review due to an error
SMTP Error: Could not authenticate.

The Artist has been notified of your new review. Thank you so much for your contribution to the site!

The Label has NOT been notified of your new review at due to an error

SMTP Error: The following recipients failed: wasserwirbel@gmail.com
SMTP server error: acidic.aquariusstorage.com (www.chaindlk.com) [69.16.232.8] is currently 550-not permitted to relay through this server. Perhaps you have not logged 550-into the pop/imap server in the last 30 minutes or do not have SMTP 550 Authentication turned on in your email client.


xxxxxxxx@gmail.com has NOT been notified of your new review due to an error
The following From address failed: from@chaindlk.com
SMTP server error: sender already given

 

I did some research and found a post on a website called phpfreaks.com that suggested using sleep() between every email but that didn't work either. I am wondering whether it is a problem on my end (the code I wrote) and was hoping somebody could take a look and offer some advice.

 

Thanks in advance for taking the time.

 

            // Send E-Mail to Webmasters! 
            $mail->Subject = 'NEW REVIEW: '.$_POST["artist"].( isset($_POST["title_work"]) ? ' - "'.$_POST["title_work"].'"' : '' ); 
            $body = 'NEW REVIEW:<br /><br /> 
Artist: '.$_POST["artist"].'<br /> 
Title: '.( isset($_POST["title_work"]) ? $_POST["title_work"] : '' ).'<br /> 
Label: '.$_POST["label"].'<br /> 
Distributor: '.$_POST["distributor"].'<br /> 
Review written by: '.$_SESSION["signature"].' (please forward all relevant emails to this person)<br /> 
<br /> 
Review: 
TESTING<br /> 
<br /> 
Go to the following link to view the review: '.$mail_link.'<br /> 
<br /> 
Date: '.$date.''; 

            $body = eregi_replace("[\]",'',$body); 
            $mail->AddReplyTo($_SESSION["email"],''); 
            $mail->AddReplyTo($email_notification_username1.'@'.$email_notification_domain1,''); 
            $mail->AddAddress($email_notification_username1.'@'.$email_notification_domain1,''); 
            $mail->MsgHTML($body); 
            if(!$mail->Send()) { 
                $notification_results = '<li>webmasters have <b>NOT</b> been notified of your new review due to an error<br /><br />'.$mail->ErrorInfo.'</li><br />'; 
            } else { 
                $notification_results = '<li>webmasters have been notified of your new review. Thank you so much for your contribution to the site!</li><br />'; 
                sleep(3); 
            } 


            if ( !empty($_POST["email_artist"]) ) { 
                // email band 
                $mail->Subject = 'a REVIEW of a product you were involved with ('.$_POST["artist"].( isset($_POST["title_work"]) ? ' - '.$_POST["title_work"] : '' ).') has been posted at the Chain D.L.K. website'; 
                $body = 'A new REVIEW of '.$_POST["artist"].'\'s '.( isset($_POST["title_work"]) ? $_POST["title_work"] : '' ).' has been posted at the Chain D.L.K. website by '.$_SESSION["signature"].' on '.$date.' and you may read it at '.$mail_link.'.<br />'; 
                $body = eregi_replace("[\]",'',$body); 
                $mail->AddReplyTo($_SESSION["email"],''); 
                $mail->AddReplyTo($email_notification_username1.'@'.$email_notification_domain1,''); 
                $mail->AddAddress($_POST["email_artist"],''); 
                $mail->MsgHTML($body); 
                if(!$mail->Send()) { 
                    $notification_results .= '<li><span class="red">The Artist has <b>NOT</b> been notified of your new review at <b>'.$_POST["email_artist"].'</b> due to an error<br /><br />'.$mail->ErrorInfo.' You might want to manually notify '.$_POST["email_artist"].' personally.</span></li><br />'; 
                } else { 
                    $notification_results .= '<li><span class="green">The Artist has been notified of your new review at <b>'.$_POST["email_artist"].'</b>. Thank you so much for your contribution to the site!</span></li><br />'; 
                    sleep(3); 
                } 
            } else { 
                if ( $type == "music" ) 
                    $notification_results .= '<li><span class="orange">You have not entered an Artist Email contact therefore we were unable to notify the artist of this review. Please contact the artist (or their publicist) manually to let them know about this review and the next time please try to enter an Artist Email address so that they can be automatically notified. Thank you for your efforts.</span></li><br />'; 
            } 

            if ( !empty($_POST["email_label"]) ) { 
                // email label 
                $mail->Subject = 'a REVIEW of a product you were involved with ('.$_POST["artist"].( isset($_POST["title_work"]) ? ' - '.$_POST["title_work"] : '' ).') has been posted at the Chain D.L.K. website'; 
                $body = 'A new REVIEW of '.$_POST["artist"].'\'s '.( isset($_POST["title_work"]) ? $_POST["title_work"] : '' ).' has been posted at the Chain D.L.K. website by '.$_SESSION["signature"].' on '.$date.' and you may read it at '.$mail_link.'.<br />'; 
                $body = eregi_replace("[\]",'',$body); 
                $mail->AddReplyTo($_SESSION["email"],''); 
                $mail->AddReplyTo($email_notification_username1.'@'.$email_notification_domain1,''); 
                $mail->AddAddress($_POST["email_label"],''); 
                $mail->MsgHTML($body); 
                if(!$mail->Send()) { 
                    $notification_results .= '<li><span class="red">The Label has <b>NOT</b> been notified of your new review at <b>'.$_POST["email_label"].'</b> due to an error<br /><br />'.$mail->ErrorInfo.' You might want to manually notify '.$_POST["email_artist"].' personally.</span></li><br />'; 
                } else { 
                    $notification_results .= '<li><span class="green">The Label has been notified of your new review at <b>'.$_POST["email_label"].'</b>. Thank you so much for your contribution to the site!</span></li><br />'; 
                    sleep(3); 
                } 
            } else { 
                if ( $type == "music" && isset($_POST["label"]) ) 
                    $notification_results .= '<li><span class="orange">You have not entered a Label Email contact therefore we were unable to notify the artist of this review. Please contact the label (or their publicist) manually to let them know about this review and the next time please try to enter a Label Email address so that they can be automatically notified. Thank you for your efforts.</span></li><br />'; 
            } 

 

I started this thread and received some good advice from others.  One recommendation was to use swiftmailer.    I found that this program worked better than PHPMailer.  I would try that as well as using the sleep function at regular intervals of email batches.

I believe I found the solution and so I wanted to post it here.

 

It appears that both the FROM and the email address of the email account that is being used as the SMTP account have to exists. It was obvious to me that the latter had to exist but I thought that I could set the former to a non-existant 'DO-NOT-REPLY@domain.com' email in order to avoid all notification replies going to the webmaster when they should go to somebody else...

 

So:

 

$mail->Username  = "MUST-EXIST@domain.com"; // SMTP account username

$mail->Password  = "phpmailer@1234"; // SMTP account password

$mail->SetFrom("MUST-EXIST@domain.com", "NAME HERE")

 

Thanks

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.