SwiftMailer Connection could not be established wi

2019-09-10 03:46发布

I am getting an unexpected problem with emails being sent from my site. It had been working fine for some time and all of a sudden seems to have stopped for no apparent reason.

[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

In my web.php

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

What could have happened for this to stop working and how should I be fixing it?

I am using google apps for my emails, but I have always used this config where I connect to my mail server. I'm not sure why it suddenly stopped working.

2条回答
一纸荒年 Trace。
2楼-- · 2019-09-10 04:03

it's looking for the server mail.website.com but isn't able to resolve it. use this domain smtp.gmail.com and port 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 . ']'
    );
}

So you either need to input a valid smtp server or wrap the send() line in a try/catch to catch the exception and either log it somewhere or ignore it. Please checkif the port you use is really the port used by your mail server.

查看更多
淡お忘
3楼-- · 2019-09-10 04:21

Same thing thing happened to me in yii , couple of days ago.Solved it by changing the port.

Try,

'port' => 26,
查看更多
登录 后发表回答