Page 1 of 1

Response Error 451 Too Many Connections?

Posted: Thu Jul 12, 2007 3:56 am
by snursita
Hi, I'm using swift version 2.1.16, php 4.4.4-8, SMTP connection.

Problem: Sometimes I get this message when sending emails with the code below. When I don't get this error, the email is delivered late (1-2 hour delay). This never happened before; only happened recently (about 1 week). My web host technical support said that the queue in mail system is full. But I wasn't sending a large amount of email, it was only a notification to 5-10 people that a form is approved.

Question:
1. Is there something wrong in my code / swift that could cause this? Or is this purely the SMTP server problem? Why is it happening recently? Why it said "There are currently too many connections from your IP/IP block"?
2. Why I also received email with subject: "0" and content: "0"?

Image
Errors:
Array ( [0] => Array ( [num] => 0 [time] => 0.41449900 1184129232 [message] => MTA Error (Swift was expecting response code 250 but got 0): ) ) .
Log: Array ( [0] => Array ( [command] => [time] => 0.41429200 1184129232 [response] => 451 TOO_MANY_CONNECTIONS(451) - There are currently too many connections from your IP/IP block. Please try again later. ) [1] => Array ( [command] => HELO http://www.mydomain.com [time] => 0.41444000 1184129232 [response] => ) )

Code: Select all

class send {

function send($content=0,$subject=0,$destination=0){
    global $mailer;
    $smtpHost = "mydomain.com";
    $mailer = new Swift(new Swift_Connection_SMTP($smtpHost)); 

    $from = "email@mydomain.com";
    $replyto = "me@mydomain.com";
    $sendto = array($destination);
    $_SESSION['content'] = $content;
    $emailSubject = $subject;
    
    #--- This part is to replace all image source and attach it to email
    $parser = new HTML_SAXParser();
    $parser->initFunc('changeImageSource');
    $parser->parseString($_SESSION['content']);
    
    if (!$mailer->hasFailed()) {
        $mailer->addPart($_SESSION['content'], 'text/html');
        $mailer->setReplyTo($replyto);
        $success = $mailer->send(
            array($replyto),
            $from,
            $emailSubject
        );
        $success = $mailer->send(
            $sendto,
            $from,
            $emailSubject
        );
        $mailer->close();
	if($success) return "Mail sent!";
    }
    else {
        echo ("<br>Errors: ".print_r($mailer->errors, 1).". <br>Log: ".print_r($mailer->transactions, 1));
        $mailer->close();
    }
}

}
// $contentAll, $subject and $receiveremail is previously set
$send1 = new send;
$send1->send($contentAll,$subject,$receiveremail);

Trial with version 3.2.6 also doesn't work

Posted: Thu Jul 12, 2007 4:24 am
by snursita
I tried to send the email with Swift 3.2.6 it also doesn't work. Please help! Thanks!
Fatal error:
Uncaught Error of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response []]
@0 swiftsend::swiftsend() in /home/www/testswift.php on line 3
@1 swift::swift() in /home/www/lib/swiftsend.php on line 21
@2 swift::connect() in /home/www/lib/Swift-3.2.6/lib/Swift.php on line 111
@3 swift::handshake() in /home/www/lib/Swift-3.2.6/lib/Swift.php on line 245

in /home/www/lib/Swift-3.2.6/lib/Swift/Errors.php on line 99

Code: Select all

// testswift.php
require_once "WebConfig.php";
$ss = new SwiftSend();
echo $ss->send("Hello sari!","just hello",array("myemail@mydomain.com"));

// WebConfig.php
define ("INT_LIB_PATH", INT_HOME_PATH . "lib/");
define ("SWIFT", INT_LIB_PATH . "Swift-3.2.6/lib/");
require_once SWIFT . "Swift.php";
require_once SWIFT . "Swift/Connection/SMTP.php";
require_once SWIFT . "Swift/Plugin/AntiFlood.php";
require_once INT_LIB_PATH . "SAXparser/SAXParser.php";
require_once INT_LIB_PATH . "swiftsend.php";

// swiftsend.php
function changeImageSource($tag, $attributes, $readSize) {
  global $swiftmessage;

  if ($tag=='img' && isset($attributes['src'])) {
    $imgsrc = $attributes['src'];
		$img =& new Swift_Message_Image(new Swift_File($imgsrc));
		$src = $swiftmessage->attach($img);
  }
}

class SwiftSend {
	var $swift;

	function SwiftSend() {
		$smtp_path = "mydomain.com"; 
		$this->smtp =& new Swift_Connection_SMTP($smtp_path, 25);
		$this->swift =& new Swift($this->smtp);
		$this->swift->attachPlugin(new Swift_Plugin_AntiFlood(50, 10), "anti-flood");	
	}
	
	function send($message, $subject, $arrayto=null, $replyto='', $arraycc=null, $arraybcc=null) {
		global $swiftmessage;
		$this->swift->log->enable();

		$sender = new Swift_Address("sender@mydomain.com", "Sender Email");
		if(!empty($replyto)) {
			$replyto = new Swift_Address("replyto@mydomain.com", "Reply to me");
		}
		$swiftmessage =& new Swift_Message($message);
		$swiftmessage->setReplyTo($replyto);
		$swiftmessage->setSubject($subject);

                $parser = new HTML_SAXParser();
                $parser->initFunc('changeImageSource');
                $parser->parseString($swiftmessage->getBody());

		$recipients =& new Swift_RecipientList();
		if(!is_null($arrayto)) {
			foreach($arrayto as $toemail) {
				$recipients->addTo($toemail);
			}
		}
		if(!is_null($arraycc)) {
			foreach($arraycc as $ccemail) {
				$recipients->addCc($ccemail);
			}
		}
		if(!is_null($arraybcc)) {
			foreach($arraybcc as $bccemail) {
				$recipients->addBcc($bccemail);
			}
		}

		if ($this->swift->send($swiftmessage, $recipients, $sender))
		{
			return "Message sent";
		}
		else
		{
			return "<font color=red>Sorry, the system failed to send your email</font>.<br>Errors: ".$this->swift->log->dump();
		}
		$this->swift->log->disable();
		$this->swift->disconnect();
	}
}

Posted: Thu Jul 12, 2007 5:39 am
by Chris Corbyn
Your code looks fine, I assume there's a problem with the SMTP server. Do other people connect to the same SMTP server?

Posted: Fri Jul 13, 2007 12:27 am
by snursita
Yes, it's a shared hosting. I agree with you, I also suspect that there's something wrong with the server, but I don't know what to ask the technical support because they seemed to think everything is fine. Here's their reply:
Thank you for your report. We are sorry for the inconvenience. Here's our check result.

$ telnet mydomain.com 25
Trying XXX.XX.XXX.XX...
Connected to mydomain.com.
Escape character is '^]'.
220 server206.mydomain.com ESMTP ready (Spanel SMTPD 0.4.5-sp1.3)

We also try to send an email with a new account in your domain: test@mydomain.com TO your email: myemail@mydomain.com and CC it to: test@mydomain.com and the email is sent successfully.

From that result, we conclude that there was no problem with our mail server because the email was sent without any error.

Please check again. Thanks.
I have a feeling that he doesn't understand what I meant and answers a different problem. Since it's a shared hosting, do you know how I can view all SMTP connections originated from my domain and trace what could cause the server to say "Too many connections from your IP"?

Thanks for your explanation