laravel StreamBuffer.php 第 268 行中的 Swift_TransportException:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42829812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:34:30  来源:igfitidea点击:

Swift_TransportException in StreamBuffer.php line 268:

laravellaravel-5

提问by Isis

When I try to send an email from my laravel site I get this error

当我尝试从我的 Laravel 站点发送电子邮件时,出现此错误

Swift_TransportException in StreamBuffer.php line 268: Connection could not be established with host lin01.hkdns.co.za [ #0]

StreamBuffer.php 第 268 行中的 Swift_TransportException:无法与主机 lin01.hkdns.co.za [#0] 建立连接

all my details is right. my env

我所有的细节都是正确的。我的环境

MAIL_DRIVER=smtp
MAIL_HOST=lin01.hkdns.co.za
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

In my mail.php

在我的mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

'port' => env('MAIL_PORT', 587),

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Info'),
],

'encryption' => env('MAIL_ENCRYPTION', 'tls'),

'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

'sendmail' => '/usr/sbin/sendmail -bs',

'markdown' => [
    'theme' => 'default',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

Did I miss something or is this a problem on my server?

我错过了什么还是我的服务器有问题?

回答by Jo?o Mantovani

Sometime it's possible to be "cache" in the laravel.

有时可能会在 Laravel 中“缓存”。

Use this command and try again:

使用此命令并重试:

php artisan config:clear

If not work, try to restart you xampp.

如果不起作用,请尝试重新启动您的 xampp。

Another option to check if the problem is with your host or your configuration is to use a Gmail server to send a test email.

检查问题是否与您的主机或您的配置有关的另一种选择是使用 Gmail 服务器发送测试电子邮件。

Puts this in your .env

把这个放在你的 .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls

Create or use any gmail account and enable the less secure appsmore information here

创建或使用任何Gmail帐户,并启用安全性较低的应用程序的更多信息点击这里

first login to your gmail account and under My account > Sign In And Security > Sign In to google, enable two step verification, then you can generate app password, and you can use that app password in .env file.

Your .env file will then look something like this

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.comMAIL_PORT=587[email protected]MAIL_PASSWORD=apppasswordMAIL_ENCRYPTION=tls

Don't forget to run php artisan config:cacheafter you make changes in your .env file (or restart your server).

首先登录您的gmail帐户,在我的帐户>登录和安全>登录google下,启用两步验证,然后您可以生成应用程序密码,您可以在.env文件中使用该应用程序密码。

您的 .env 文件将如下所示

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.comMAIL_PORT=587[email protected]MAIL_PASSWORD=apppasswordMAIL_ENCRYPTION=tls

php artisan config:cache在 .env 文件(或重新启动服务器)中进行更改后,不要忘记运行。

Source here

来源在这里