Page 1 of 1
SMTP with SSL seems to always fail?
Posted: Mon Mar 09, 2009 8:37 am
by kaisellgren
Hi,
I have tried a few different SMTP servers (gmail, live, etc) but everytime the script returns the following error:
Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.live.com:587 (Unknown error) in C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php on line 243
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.live.com [ #0]' in C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php:245 Stack trace: #0 C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php(80): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\AbstractSmtpTransport.php(111): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\Portable Programs\nginx\priv\swift\classes\Swift\Mailer.php(84): Swift_Transport_AbstractSmtpTransport->start() #3 C:\Portable Programs\nginx\priv\test.php(48): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in C:\Portable Programs\nginx\priv\swift\classes\Swift\Transport\StreamBuffer.php on line 245
I have OpenSSL extension running and the application installed as well and to me it OpenSSL functions seem to work in general.
What could be the reason for this ?
Re: SMTP with SSL seems to always fail?
Posted: Mon Mar 09, 2009 8:46 am
by Chris Corbyn
It seems to dislike the version of SSL being used. Perhaps the OpenSSL library your PHP installation is built against is out of date?
Basically I think your client connection uses SSL2 whereas the remote server is trying to use SSL23, or vice versa. It's certainly an incompatibility with the libraries on each end.
Perhaps this is something I can fix at a code level... I'll look into it. I have a feeling you can change the "ssl://" part of my code to "sslv2://". If that works I can find out what my most portable course of action is.
Re: SMTP with SSL seems to always fail?
Posted: Mon Mar 09, 2009 9:07 am
by kaisellgren
With sslv3:
SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in
with sslv2:
Warning: fsockopen() [function.fsockopen]: SSL: The operation completed successfully.

?
I don't understand. Warning, SSL operation completed successfully x)
EDIT: I think it's because of me. I am running vista x64, nginx x64, openssl x64 and php x64 so maybe there are some problems on my side.
Re: SMTP with SSL seems to always fail?
Posted: Fri Apr 03, 2009 1:39 pm
by John Cartwright
I've gotten the same error when connecting to a gmail account (using latest Swift version of v4.0.3), OpenSSL is installed, and SSL appears as a registered transport. Any furthur information on the matter would be greatly appreciated.
My OpenSSL information, as per phpinfo()
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
My output includes
Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:587 (Unknown error) in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [ #0]' in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php:245 Stack trace: #0 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php(80): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/AbstractSmtpTransport.php(111): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Mailer.php(84): Swift_Transport_AbstractSmtpTransport->start() #3 /home/backdoor/public_html/jcartdev/autoresponder/index.php(76): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} thrown in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 245
I have tried changing the protocal parameter to use sslv2 but that resulted in an fsockopen timeout.
Code: Select all
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'sslv2')
->setUsername($account['email'])
->setPassword($account['password']);
Warning: fsockopen() [function.fsockopen]: SSL: connection timeout in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Warning: fsockopen() [function.fsockopen]: unable to connect to sslv2://smtp.gmail.com:587 (Unknown error) in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 243
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [ #0]' in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php:245 Stack trace: #0 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php(80): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/AbstractSmtpTransport.php(111): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Mailer.php(84): Swift_Transport_AbstractSmtpTransport->start() #3 /home/backdoor/public_html/jcartdev/autoresponder/index.php(78): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} thrown in /home/backdoor/public_html/jcartdev/library/Swift/classes/Swift/Transport/StreamBuffer.php on line 245
Re: SMTP with SSL seems to always fail?
Posted: Fri Apr 03, 2009 1:52 pm
by John Cartwright
Hmm, after reading
http://gmail.google.com/support/bin/ans ... swer=13287 again, they say
Also, if you're having trouble sending mail but you've confirmed that encyrption is active for SMTP in your mail client, try to configure your SMTP server on a different port: 465 or 587.
I switched to port 465 which worked fine with SSL.

Re: SMTP with SSL seems to always fail?
Posted: Fri Apr 03, 2009 6:41 pm
by Chris Corbyn
Yes, you've always needed to use port 465 with Swift Mailer. 587 is the one you use if Swift Mailer will switch the TLS once a non-encrypted connection has been established. Swift Mailer can't do this (yet).
Re: SMTP with SSL seems to always fail?
Posted: Fri Apr 03, 2009 6:52 pm
by John Cartwright
Thanks for the clarification. Hopefully it will save someone as big of a headache as mine

Re: SMTP with SSL seems to always fail?
Posted: Mon Aug 24, 2009 2:36 am
by slawkens
John Cartwright wrote:Thanks for the clarification. Hopefully it will save someone as big of a headache as mine

hey
I just registered there to say thanks to
John Cartwright. This port problem saved me a lot of time!!!(Last 2 days)!! Thanks!!!!!!!
Re: SMTP with SSL seems to always fail?
Posted: Mon Dec 14, 2009 7:10 am
by pablopablo
I had a similar problem with a TLS service that connected plainly and then wanted to talk encryption. I just couldn't get it to work but in the end came across a piece of code that worked for me.
The OpenSSL library used by PHP doesn't support TLS connections that want to upswitch mid-stream so you have to do it natively using a socket-based connection. I bumped into this piece of code and it solved my problem perfectly. Maybe this is something that SwiftMailer could leverage.
http://forum.powweb.com/showthread.php?t=73406
Re: SMTP with SSL seems to always fail?
Posted: Thu May 20, 2010 2:10 am
by Benjamin
I'm running into this too using TLS:
[text]Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number[/text]
I can't use port 465. The server won't respond on that port.
Re: SMTP with SSL seems to always fail?
Posted: Sat May 22, 2010 2:43 pm
by JGarrido
I have the same problem as Benjamin; what would one recommend? The necessity to connect via TLS on port 587 is non-negotiable for me, is this just not possible using PHP?