简体   繁体   English

无法在 Laravel 中发送 SSL/TLS smtp 电子邮件

[英]Unable to send SSL/TLS smtp emails in Laravel 7

My config:我的配置:

PHP version: 7.4.5 PHP 版本:7.4.5

Laravel version: 7 Laravel 版本:7

Swiftmailer version: 6.2.3 Swiftmailer 版本:6.2.3

Observed behaviour观察到的行为

Swift_TransportException Connection could not be established with host... :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

Expected behavior预期行为

Working -> I think there was a breaking change in underlying libs and used encryption methods, cause I have systems where it is working with the exactly same swiftmailer version.工作-> 我认为底层库和使用的加密方法发生了重大变化,因为我的系统使用完全相同的 swiftmailer 版本。

Example to reproduce重现的例子

  1. Install the latest Laravel 7.安装最新的 Laravel 7。
  2. Create proper configs and mails.创建适当的配置和邮件。
  3. Try to send email with port 587 and tls enabled.尝试发送 email 并启用端口 587 和 tls。 Error: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed错误: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
  4. Try to send email with port 465 and ssl enabled.尝试发送 email 并启用端口 465 和 ssl。 Error: Connection could not be established with host... :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed Error: Connection could not be established with host... :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

Please note that:请注意:

  1. Configs are 100% validated and I can send emails from many different systems, but not using this library -> swiftmailer -> used_by -> laravel.配置是 100% 验证的,我可以从许多不同的系统发送电子邮件,但不能使用这个库 -> swiftmailer -> used_by -> laravel。
  2. I've tried different smtp mailing vendors and the results are identical.我尝试了不同的 smtp 邮件供应商,结果是相同的。

What am I doing wrong here?我在这里做错了什么?

The solution was really trivial.解决方案真的很简单。

What was needed to solve this problem, was to set up MAIL_ENCYRPTION to tcp in .env .解决此问题所需的是将MAIL_ENCYRPTION设置为tcp中的.env instead of tls or ssl on corresponding ports.而不是相应端口上的tlsssl

For some strange reasons, setting tls (no matter version) or ssl , with proper ports didn't work.由于一些奇怪的原因,使用正确的端口设置tls (无论版本)或ssl不起作用。

Therefore, if you are experiencing these types of problems, please set MAIL_ENCYRPTION=tcp - this should solve your errors.因此,如果您遇到这些类型的问题,请设置MAIL_ENCYRPTION=tcp - 这应该可以解决您的错误。

Happy coding...快乐的编码...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM