【问题标题】:Laravel 5 Connection could not be established with host smtp.gmail.com in windows 7Laravel 5 无法在 Windows 7 中与主机 smtp.gmail.com 建立连接
【发布时间】:2016-08-08 05:03:27
【问题描述】:

当我在 laravel 中使用邮件功能时,显示此错误

无法与主机smtp.gmail.com建立连接[连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。

10060]

这是我的.env 文件配置

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myacount@gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls

【问题讨论】:

  • 尝试用 MAIL_DRIVER=sendmail 改变这个 MAIL_DRIVER=smtp
  • 再次显示此错误
  • ok 设置这个 'encryption' => 'ssl', and env('MAIL_ENCRYPTION','tls'),
  • 并尝试启用此功能google.com/settings/security/lesssecureapps
  • 再次显示此错误

标签: php laravel email laravel-5 laravel-5.2


【解决方案1】:
MAIL_DRIVER='sendmail'
MAIL_HOST='smtp.gmail.com' Or '173.194.65.108'
MAIL_PORT=587
MAIL_USERNAME='expense@blabla.com'
MAIL_PASSWORD="secret"
MAIL_ENCRYPTION="tls"
  1. 这里重要的是驱动程序 - sendmail
  2. 清除您的配置 -
Artisan::call('view:clear');
 Artisan::call('route:clear');
 Artisan::call('config:clear');
 Artisan::call('cache:clear');
 Artisan::call('config:cache');

N.B - 您的 cmd 将类似于:php artisan view:clear .....etc。清除您在 .env 中更改的缓存很重要。我个人也重新启动 xampp,因为我在某处读取 .env 文件加载时 apache 启动!

  1. 现在尝试发送邮件,如果您的网络管理员没有阻止它应该可以工作[无意中!在我的情况下,他甚至不知道它停止发送邮件是为了哪个更改]

  2. 我在 laravel 5.2 中使用了这些步骤,它运行良好,但最近 google 或我的网络管理员更改了一些内容,因此它不能从 xampp 发送邮件,但在共享主机中运行良好。

N.B- 我列出这些是因为至少它适用于我花了很多时间进行故障排除的真实主机。

【讨论】:

  • 非常感谢。但告诉我错误:Process could not be started [The system cannot find the path specified]
【解决方案2】:

只需重新启动您的 XAMPP(Apache 和 MySQL),然后再次运行 PHP Artisan,一切顺利。

【讨论】:

    【解决方案3】:

    通过将以下行添加到您的 composer.json 文件中,确保将 Guzzle 安装到您的项目中:

    "guzzlehttp/guzzle": "~5.3|~6.0"
    

    参考Connection could not be established with host smtp.gmail.com Laravel

    【讨论】:

      猜你喜欢
      • 2016-02-07
      • 1970-01-01
      • 2021-01-04
      • 2015-02-27
      • 2017-12-08
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      • 2019-03-01
      相关资源
      最近更新 更多