CakePHP SwiftMailer SMTP TLS OpenSSL Error SSL3_GET_RECORD:wrong version number

情到浓时终转凉″ 提交于 2019-12-19 07:19:31

问题


I'm attempting to send an email using the CakePHP SwiftMailer component I found here: http://bakery.cakephp.org/articles/sky_l3ppard/2009/11/07/updated-swiftmailer-4-xx-component-with-attachments-and-plugins

The server I'm sending to is using SMTP with TLS over port 25. Here's the error I get when I attempt to send a mail:

Notice (8): Trying to get property of non-object [APP/views/helpers/hdl_session.php, line 14]

Warning (2): stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): stream_socket_client() [function.stream-socket-client]: Failed to enable crypto [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): stream_socket_client() [function.stream-socket-client]: unable to connect to tls://mail.aedisit.com:25 (Unknown error) [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): Illegal offset type in isset or empty [CORE/cake/libs/i18n.php, line 177]

Warning (2): Cannot modify header information - headers already sent by (output started at /srv/www/stage/hypercool/cake/libs/debugger.php:673) [CORE/cake/libs/controller/controller.php, line 742]

Here's the OpenSSL info from my phpinfo:

openssl
OpenSSL support     enabled
OpenSSL Library Version     OpenSSL 0.9.8o 01 Jun 2010
OpenSSL Header Version  OpenSSL 0.9.8o 01 Jun 2010 

And some more info from my phpinfo:

PHP Version 5.3.5-1ubuntu7.2
Registered Stream Socket Transports     tcp, udp, unix, udg, ssl, sslv3, sslv2, tls 

Any help here is greatly appreciated :-)

EDIT:

SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

This seems to be the root of the problem. Anyone know what exactly this means?


回答1:


We have resolved this issue. The problem appeared to be with our SSL version and the connect method of SwiftMailer. The SwiftMailer component was attempting to connect using TLS, when instead it first needed to connect in plaintext, and then initiate the TLS connection. Hope this helps anyone else with this problem.




回答2:


Update your SwiftMailer libs. I recently ran into this exact problem with SwiftMailer 4.0.6 and upgraded to 4.1.6 - now it works like a charm :)




回答3:


I have resolved the issue. Here is the configuration you can use:

'default' => [
    'className' => 'Smtp',
    'host' => 'ssl://smtp.gmail.com',
    'username' => 'GMAIL_EMAIL_ADDRESS',
    'password' => 'GMAIL_PASSWORD',
    'port' => 465, //here was the problem
    'timeout' => 50,
    'client' => null,
    'tls' => null,
    'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],

If you are using EC2 ( AWS Instance ) then you have to allow the 465 port ( create Custom TCP Rule for SMTP - port 25 or SMTPS - port 465 )



来源:https://stackoverflow.com/questions/7285764/cakephp-swiftmailer-smtp-tls-openssl-error-ssl3-get-recordwrong-version-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!