SMTP with SSL seems to always fail?

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
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

SMTP with SSL seems to always fail?

Post 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 ?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: SMTP with SSL seems to always fail?

Post 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.
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: SMTP with SSL seems to always fail?

Post 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.
:D ?

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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: SMTP with SSL seems to always fail?

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: SMTP with SSL seems to always fail?

Post 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. :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: SMTP with SSL seems to always fail?

Post 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).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: SMTP with SSL seems to always fail?

Post by John Cartwright »

Thanks for the clarification. Hopefully it will save someone as big of a headache as mine :)
slawkens
Forum Newbie
Posts: 1
Joined: Mon Aug 24, 2009 2:33 am

Re: SMTP with SSL seems to always fail?

Post 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!!!!!!!
pablopablo
Forum Newbie
Posts: 1
Joined: Wed Dec 09, 2009 11:31 am

Re: SMTP with SSL seems to always fail?

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: SMTP with SSL seems to always fail?

Post 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.
JGarrido
Forum Newbie
Posts: 3
Joined: Fri Aug 22, 2008 12:42 pm

Re: SMTP with SSL seems to always fail?

Post 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?
Post Reply