无法与主机建立 SwiftMailer 连接

SwiftMailer Connection could not be established with host

从我的站点发送电子邮件时遇到意外问题。它已经工作了一段时间,突然间似乎无缘无故地停止了。

[Swift_TransportException] exception 'Swift_TransportException' with message 'Connection could not be established with host [Connection timed out #110]' in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:265

在我的web.php

'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'mail.website.com',
        'username' => 'username',
        'password' => 'password',
        'port' => '587',
        'encryption' => 'tls',
        ],

为什么会停止工作?我应该如何修复它?

我正在为我的电子邮件使用 google 应用程序,但我一直在连接到我的邮件服务器时使用此配置。我不确定它为什么突然停止工作。

它正在寻找服务器 mail.website.com 但无法解析它。 使用此域 smtp.gmail.com 和端口 25 or 465.

if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
{
  throw new Swift_TransportException(
    'Connection could not be established with host ' . $this->_params['host'] .
    ' [' . $errstr . ' #' . $errno . ']'
    );
}

因此您需要输入有效的 smtp 服务器或将 send() 行包装在 try/catch 中以捕获异常并将其记录在某处或忽略它。 请检查您使用的端口是否真的是您的邮件服务器使用的端口。

我在 yii 中发生了同样的事情,几天 ago.Solved 通过更改端口。

试试,

'port' => 26,