(Swift_TransportException(代码:0):连接到 tcp://server.example.com



我们已将电子邮件服务器从一个提供商更改为另一个提供商。使用旧电子邮件设置发送的位置,但不使用新电子邮件设置发送的位置。我不确定它是拉拉维尔服务器还是电子邮件服务器。

我将在这里使用我的域作为:example.com

我已经更改了 .env 中的新电子邮件设置:

MAIL_DRIVER=smtp
MAIL_HOST=server.example.com
MAIL_PORT=465
MAIL_USERNAME=no-reply@example.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=ssl

当我们发送电子邮件时,我们会在 Laravel 中收到此异常.log

production.ERROR: Connection to tcp://server.example.com:465 Timed Out {"exception":"[object] (Swift_TransportException(code: 0): Connection to tcp://server.example.com:465 Timed Out at /var/www/example.com/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:473, Swift_IoException(code: 0): Connection to tcp://server.example.com:465 Timed Out at /var/www/example.com/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:166)

我也尝试过使用 tls 而不是 ssl 但出现相同的错误。

我已经使用提供商的给定设置在 thunderbird 中配置了该电子邮件 no-replay@example.com 并正常工作。

电子邮件设置:

incoming: IMAP server.example.com 993 SSL/TLS Encrypted password 
outgoing: SMTP server.example.com 465 SSL/TLS Encrypted password
username (email address) and password.

我错过了一些????

就我而言,该错误具有误导性。这不是超时,而是由错误的加密设置引起的。

就我而言,我需要设置MAIL_ENCRYPTION=ssl

如果您从Gmail帐户发送电子邮件,请尝试此操作

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=your_email (like abc@gmail.com)
MAIL_PASSWORD=secret (when you create a app in your google account then  get a app secret)
MAIL_ENCRYPTION=ssl

如果您在Gmail中执行此操作,则可以轻松地从Gmail帐户发送邮件

正如Paolo所说,将MAIL_ENCRYPTION更改为ssl对我有用,但只有在运行此命令后也php artisan config:cache

最新更新