PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 21, 2014 9:46 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Mar 07, 2008 8:44 am 
Offline
Forum Newbie

Joined: Fri Mar 07, 2008 8:35 am
Posts: 1
i'm having problems connecting to my an SMTP Server using TLS:

this is my code:

Syntax: [ Download ] [ Hide ]
 
require_once "Swift/lib/Swift.php";
require_once "Swift/lib/Swift/Connection/SMTP.php";
 
$log = Swift_LogContainer::getLog();
$log->setLogLevel(Swift_Log::LOG_EVERYTHING);
$log->setMaxSize(200);
 
try {
        $smtp = new Swift_Connection_SMTP("smtp.unibe.ch", 587, Swift_Connection_SMTP::ENC_TLS);
        $smtp->setUsername("user");
        $smtp->setpassword("pass");
 
        $swift = new Swift($smtp);
 
        $message = new Swift_Message("test", "Test");
 
        $swift->send($message, "rcpt@mail.com", "sender@mail.com");
} catch (Swift_ConnectionException $e) {
        echo "There was a problem communicating with SMTP: " . $e->getMessage();
} catch (Swift_Message_MimeException $e) {
        echo "There was an unexpected problem building the email:" . $e->getMessage();
}
 
echo $log->dump(true);
 


This is the output of the script (with logging):
Syntax: [ Download ] [ Hide ]
 
There was a problem communicating with SMTP: The SMTP connection failed to start [tls://smtp.unibe.ch:587]: fsockopen returned Error Number 0 and Error String ''
Log Information
 
++ Log level changed to 4
++ Forcing ESMTP mode.  HELO is EHLO.
++ Forcing ESMTP mode.  HELO is EHLO.
++ Trying to connect...
++ Trying to connect to SMTP server at 'tls://smtp.unibe.ch:587
!! The SMTP connection failed to start [tls://smtp.unibe.ch:587]: fsockopen returned Error Number 0 and Error String '
'
 
++ Log level changed to 4 ++ Forcing ESMTP mode. HELO is EHLO. ++ Forcing ESMTP mode. HELO is EHLO. ++ Trying to connect... ++ Trying to connect to SMTP server at '
tls://smtp.unibe.ch:587 !! The SMTP connection failed to start [tls://smtp.unibe.ch:587]: fsockopen returned Error Number 0 and Error String ''
 


the port is likely to be correct (can connect to it with telnet)

phpinfo shows that php is compiled with OpenSSL 0.9.8g

furthermore it is possible for me to connect to that server via TLS with the following command from
the shell of the same machine as the script above is running on:

Syntax: [ Download ] [ Hide ]
 
openssl s_client -starttls smtp -crlf -connect smtp.unibe.ch:25
 


Can somebody give me a hint to what i'm doing wrong?

Thanks in advance,

Gabe


Top
 Profile  
 
PostPosted: Tue Apr 29, 2008 11:36 am 
Offline
Forum Newbie

Joined: Tue Apr 29, 2008 11:35 am
Posts: 1
I am having the same exact problem. Did you find a solution?


Top
 Profile  
 
PostPosted: Tue Apr 29, 2008 12:23 pm 
Offline
Forum Newbie

Joined: Tue Apr 29, 2008 12:17 pm
Posts: 1
My code is identical to yours and getting same error. I am able to use the test files - Smoke/TestConfiguration and send the test mails successfully to gmail on port 465. But putting in our mail.actifi.com server and login/port gives me the same error you are getting.


Top
 Profile  
 
PostPosted: Tue Apr 29, 2008 8:31 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
It sounds as though this server doesn't take connections with TLS at connection-time, but actually requires STARTTLS. Swift version 3 does not support STARTTLS since it was not possible at the time due to PHP limitations. There's a subtle difference between establishing a connection using TLS and using STARTTLS within a connection.

With the former Swift simply initiates the connection with TLS enabled.
With STARTTLS the client (Swift) has to connection unencrypted and then "switch" to TLS whilst remaining connected. This switching wasn't possible to do when I wrote version 3.


Top
 Profile  
 
PostPosted: Thu Jan 22, 2009 4:06 am 
Offline
Forum Newbie

Joined: Thu Jan 22, 2009 4:04 am
Posts: 1
Ok, thanks.

Does this work now with version 4 beta?
Download here: viewtopic.php?f=52&t=93049

Thanks.


Top
 Profile  
 
PostPosted: Thu Jan 22, 2009 7:05 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
STARTTLS is not supported, even in the beta. In theory it can be but I need to make few changes for it to work so it will have to wait for now I'm afraid. When I wrote the current version it was impossible to do with PHP, but now the required functions exist should I choose to do this :)


Top
 Profile  
 
PostPosted: Sat May 22, 2010 6:22 pm 
Offline
Forum Newbie

Joined: Fri Aug 22, 2008 12:42 pm
Posts: 3
Chris Corbyn wrote:
STARTTLS is not supported, even in the beta. In theory it can be but I need to make few changes for it to work so it will have to wait for now I'm afraid. When I wrote the current version it was impossible to do with PHP, but now the required functions exist should I choose to do this :)

Please 'choose to do this'!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group