Page 1 of 1

Swiftmail error in establishing connection

Posted: Tue May 22, 2007 7:30 am
by getrajeshonline
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi friends,

I'm new to swiftmail.
I tried in many ways to send emails, using smtp and sendmail, both failed.
My server is Linux, PhP5

following are the errors, please help.

[b]Error while using smtp.gmail.com :
[/b]Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [tls://smtp.gmail.com:465]: fsockopen returned Error Number 111 and Error String 'Connection refused'' in /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php:277 Stack trace:
#0 /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php(277): Swift_Connection_SMTP::start()
#1 /home/heeragroup/swiftmail/lib/Swift.php(220): Swift_Connection_SMTP->start()
#2 /home/heeragroup/swiftmail/lib/Swift.php(97): Swift->connect()
#3 /home/heeragroup/swiftmail/test1.php(12): Swift->__construct(Object(Swift_Connection_SMTP))
#4 {main} thrown in /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php on line 277

[b]Error while using my own smtp server :[/b]
Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [tls://mail.smcsindia.com:465]: fsockopen returned Error Number 110 and Error String 'Connection timed out'' in /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php:277 Stack trace:
#0 /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php(277): Swift_Connection_SMTP::start()
#1 /home/heeragroup/swiftmail/lib/Swift.php(220): Swift_Connection_SMTP->start()
#2 /home/heeragroup/swiftmail/lib/Swift.php(97): Swift->connect()
#3 /home/heeragroup/swiftmail/testsendmail.php(13): Swift->__construct(Object(Swift_Connection_SMTP))
#4 {main} thrown in /home/heeragroup/swiftmail/lib/Swift/Connection/SMTP.php on line 277

[b]Error while using sendmail option :[/b]
Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'There was a problem reading line 1 of a sendmail SMTP response. The response so far was:
[]. It appears the process has died.' in /home/heeragroup/swiftmail/lib/Swift/Connection/Sendmail.php:203 Stack trace:
#0 /home/heeragroup/swiftmail/lib/Swift/Connection/Sendmail.php(203): Swift_Connection_Sendmail::pipeOut()
#1 /home/heeragroup/swiftmail/lib/Swift/Connection/Sendmail.php(237): Swift_Connection_Sendmail->pipeOut()
#2 /home/heeragroup/swiftmail/lib/Swift.php(307): Swift_Connection_Sendmail->read()
#3 /home/heeragroup/swiftmail/lib/Swift.php(221): Swift->command('', 220)
#4 /home/heeragroup/swiftmail/lib/Swift.php(97): Swift->connect()
#5 /home/heeragroup/swiftmail/testsendmail.php(14): Swift->__construct(Object(Swift_Connection_Sendmail))
#6 {main} thrown in /home/heeragroup/swiftmail/lib/Swift/Connection/Sendmail.php on line 203

and the code is;

Code: Select all

$subj = "Testing Email";
$body = @file_get_contents("h.html") or die("Error : Couldnt get html file h.html");

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Connection/Sendmail.php";

[b]My SMTP : [/b]$smtp = new Swift_Connection_SMTP("mail.<my domain name>.com"
[b]Gmail : [/b]$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);

            $smtp->setUsername("<emailid>");
            $smtp->setpassword("<password>");
            $swift =& new Swift($smtp);
	
[b]Sendmail : [/b]$swift =& new Swift(new Swift_Connection_Sendmail(Swift_Connection_Sendmail::AUTO_DETECT));

$message =& new Swift_Message("My subject", "My body");
$recipients =& new Swift_RecipientList();
$recipients->addTo("<my email id 1>");
$recipients->addTo("<my email id 2>");
$num_sent=$swift->batchSend($message, $recipients,  new Swift_Address("<from email>", "<from name>"));
if($num_sent) echo "Success"; else echo "Failed";
Regards,
Rajesh.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 22, 2007 12:08 pm
by Chris Corbyn
Sounds as though your host is blocking connections. This could be via firewall rules or I've also had reports that PhpSuExec can cause issues creating sockets and processes. I'd ask your host if they can shed any light on why you're seeing this.

fsockopen() -- a native PHP function, is not being able to connect (Connection refused).

Swiftmail error in establishing connection

Posted: Wed May 23, 2007 2:43 am
by getrajeshonline
hi d11wtq,

Me again,
I discussed the problem of connection blocking with our web server's customer executive, and he told that they are not blocking port 25. However, they provide an SMTP server available on each of their webservers, they advised me to specify the SMTP server 'localhost'. Now I tried with the smtp server as localhost, and got a new error, as below :

Fatal error: Uncaught exception 'Swift_BadResponseException' with message 'Expected response code(s) [250] but got response [451 qq temporary problem (#4.3.0)]' in /home/heeragroup/swiftmail/lib/Swift.php:253 Stack trace:
#0 /home/heeragroup/swiftmail/lib/Swift.php(253): Swift::assertCorrectResponse()
#1 /home/heeragroup/swiftmail/lib/Swift.php(311): Swift->assertCorrectResponse(Object(Swift_Events_ResponseEvent), 250)
#2 /home/heeragroup/swiftmail/lib/Swift.php(418): Swift->command('??.', 250)
#3 /home/heeragroup/swiftmail/lib/Swift.php(472): Swift->send(Object(Swift_Message), Object(Swift_Address), Object(Swift_Address))
#4 /home/heeragroup/swiftmail/smtp.php(28): Swift->batchSend(Object(Swift_Message), Object(Swift_RecipientList), Object(Swift_Address))
#5 {main} thrown in /home/heeragroup/swiftmail/lib/Swift.php on line 253


Can you identify the the error?
Please advise me.

Posted: Wed May 30, 2007 11:36 am
by Chris Corbyn
Hi, I didn't see your message last week so sorry for lack of response.

451 almost always means that there been an internal problem/misconfiguration on the smtp server. Some servers generate a 451 with "Please try later" when they think your message is spammy too.