Uncaught Error of type [swift_badresponseexception]

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Uncaught Error of type [swift_badresponseexception]

Post by RatanK »

Hello,

I received the error shown below when trying to send a newsletter to around 380 emails. Method used was Sendmail.

Could someone kindly help me with this?


Fatal error:
Uncaught Error of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response [421 Unexpected failure, please try later]]
@0 swift::batchsend() in /home2/maitrey/public_html/phpmail/admin/send.php on line 186
@1 swift::send() in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift.php on line 548
@2 swift::command() in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift.php on line 479

in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift/Errors.php on line 99


TIA

Kind Regards
Ratna
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

PHP Version used in 4.3.10

Post by RatanK »

Forgot to mention in the earlier post, PHP version being used is 4.3.10

When I used batchSend with two email address the same code worked well, but once the # of emails being sent increased it resulted in the error.

Hope this additional info helps.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

SMTP servers typically give errors like this when they are rejecting the request deliberately, despite the fact the error doesn't tell you that. This could be due to the spam score being too high or a max number of emails being exceeded in a allocated space of time.

Web hosts often have a cap on how many emails you can send per hour. My own MX server gives similar messages if the spam score exceeds 5.0 in SpamAssassin.

Check with your host if you have a limit. It's definitely not a Swift issue.

You may want to take a look at this if you do have a limit:

http://www.swiftmailer.org/wikidocs/v3/ ... /throttler
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Error still occurs...

Post by RatanK »

Hi dw11wtq,

I have done just as you suggested, by including the "Throttler" Plugin, but it did not help the matter.

Would you suggest me using Anti Flood or contact my host provider and find out what's happening?

Any advice given would be appreciated.


Fatal error:
Uncaught Error of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response [421 Unexpected failure, please try later]]
@0 swift::batchsend() in /home2/maitrey/public_html/phpmail/admin/send.php on line 198
@1 swift::send() in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift.php on line 548
@2 swift::command() in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift.php on line 479

in /home2/maitrey/public_html/phpmail/swiftmail/lib/Swift/Errors.php on line 99

Thank you

Kind Regards
Ratna
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Code used to send email...

Post by RatanK »

Here is the code used to send the email -

Code: Select all

require_once ("../swiftmail/lib/Swift.php");
require_once ("../swiftmail/lib/Swift/Connection/Sendmail.php");
require_once ("../swiftmail/lib/Swift/Plugin/Throttler.php");


$swift =& new Swift(new Swift_Connection_Sendmail());

$throttler =& new Swift_Plugin_Throttler();
$swift->attachPlugin($throttler, "throttler");
 
// Set the number of messages per minute?
 
$throttler->setEmailsPerMinute(30); //Max of 1 email every 2 seconds
$swift->attachPlugin($throttler, "throttler");

$message =& new Swift_Message($subject, $newsletter, "text/html", "8bit", "iso-8859-2");
$message->setReturnPath("bounces@email.com");
  
$recipients =& new Swift_RecipientList();

while ($row = mysql_fetch_array($result)) 
{
     $recipients->addTo($row['email']);

     echo "<tr><td align=center>Newsletter will be sent to: <b>" . $row['email'] . "</b> </td></tr>";  
}

$number_sent = $swift->batchSend($message, $recipients, "webmaster@email.com");

echo "<tr><td>Total # of emails sent - <b>" . $number_sent . "</b></td></tr>";
  
echo "<font color=red><b>Failed recipients:</b><br /><br />";
echo implode(" ,", $swift->log->getFailedRecipients());
  
$swift->disconnect();
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It's not Swift. 421 means that the SMTP service is not available and will not process you request. Immediately after sending a 421, SMTP servers SHOULD close the connection. The server is choosing to tell you it's not available to handle your request.

What did you try with the throttler? You're still sending 30 emails per minute (== 1800 emails per hour) with that code. The throttler will not be useful unless you waited an hour (or even a day depending upon the rules of the server) before trying it and even then you need to know what speed to throttle at. You will need to contact your host.
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Regarding the throttler

Post by RatanK »

d11wtq,

Thank you for your message. I did contact my host provider and was informed that the limit was set at 500 emails per hour. So based on this I changed the setting on the throttler to send 8 emails per minute.

The question I now have is I this... I placed around 2220 emails in the recipient array and then used the batch_mail function to send the updates, after doing this, the page on firefox said 'done' as in no more information to display and that the page has been completely refreshed. Would the emails still be sent as requested at 480 per hour?

Appreciate any info you could provide here.

Kind Regards
Ratna
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Regarding the throttler

Post by Chris Corbyn »

RatanK wrote:d11wtq,

Thank you for your message. I did contact my host provider and was informed that the limit was set at 500 emails per hour. So based on this I changed the setting on the throttler to send 8 emails per minute.

The question I now have is I this... I placed around 2220 emails in the recipient array and then used the batch_mail function to send the updates, after doing this, the page on firefox said 'done' as in no more information to display and that the page has been completely refreshed. Would the emails still be sent as requested at 480 per hour?

Appreciate any info you could provide here.

Kind Regards
Ratna
You need to use ignore_user_abort() and set_time_limit(0) to make sure it keeps sending. PHP probably timed out if it just said done quickly when you queued 2200 emails. This sort of thing is *much* better handled by cron where the browser cannot influence anything (i.e. timeouts).
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Post by RatanK »

d11wtq,

This is how I modified the code to and executed it... still the same result... do not know if the emails will be delivered...

Code: Select all

$recipients =& new Swift_RecipientList();
  $rowNbr = 0;
  while ($row = mysql_fetch_array($result)) 
  {
     $recipients->addTo($row['email']);
     $rowNbr = $rowNbr + 1;
     echo "<tr><td align=center>Newsletter will be sent to: <b>" . $rowNbr . " - " . $row['email'] . "</b> </td></tr>";  
	}

  ignore_user_abort(TRUE);
  set_time_limit(0);

  $number_sent = $swift->batchSend($message, $recipients, "webmaster@email.com");

  echo "<tr><td>Total # of emails sent - <b>" . $number_sent . "</b></td></tr>";


This was the error I received when I did not add ignore_user_abort(TRUE) & set_time_limit(0) -

Code: Select all

[24-Apr-2007 09:10:08] PHP Fatal error:  <br /><strong>Uncaught Error</strong> of type [swift_connection_exception] with message [The sendmail process did not allow the command 'RSET' to be sent.]<br /> @0 swift::batchsend() in /home2/lm611002/public_html/phpmail/admin/send.php on line 199<br /> @1 swift::send() in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift.php on line 548<br /> @2 swift::reset() in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift.php on line 465<br /> @3 swift::command() in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift.php on line 361<br /><br /> in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift/Errors.php on line 99

Did not see this error after the mod. but nonetheless the browser completed refreshing the page.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Stand by for the snippet I'm about to post in this thread:

viewtopic.php?t=66818
RatanK
Forum Newbie
Posts: 7
Joined: Wed Apr 04, 2007 9:36 am

Post by RatanK »

d11wtq,

I will implement the changes as suggested but this is the error I eventually received in the previous run.

Code: Select all

[24-Apr-2007 11:16:19] PHP Fatal error:  <br /><strong>Uncaught Error</strong> of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response [500-unrecognized command
500 Too many syntax or protocol errors]]<br /> @0 swift::batchsend() in /home2/lm611002/public_html/phpmail/admin/send.php on line 202<br /> @1 swift::send() in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift.php on line 548<br /> @2 swift::reset() in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift.php on line 465<br /><br /> in /home2/lm611002/public_html/phpmail/swiftmail/lib/Swift/Errors.php on line 99

Thank you

Ratna
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The class posted in the other thread is written to deal with things like this :) It will need some work but in its current state it should prove the proof of concept. My big focus for 3.2 is to add a completely new (relatively small) set of features for the sending side of batch mailing.

I scribbled on paper last night:
  • Create a completely new class for batch mailing
    • -Can utilise throttler and antiflood
      - Kills/masks errors and picks itself back up
      - Provides details on failed recipients
      - Allows observers for error messages killed and failed recipients
      - Change batchSend() to make basic use of the new class
  • Make Swift_RecipientList iterable so mass mails do not need arrays pre-loaded

    Code: Select all

    $it =& $list->getIterator("to");
      while ($it->hasNext())
      {
        $address =& $it->getAddress();
        $swift->send( ... );
        $it->next();
      }
  • Add error constants which act as links between E_USER_ERROR codes and the Exception objects:

    Code: Select all

    define("SWIFT_BADRESPONSE_EXCEPTION", 0x....);
Post Reply