php 无法与主机 smtp.gmail.com 建立连接 [操作超时 #60]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30624194/
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
Connection could not be established with host smtp.gmail.com [Operation timed out #60]
提问by cyber8200
I can't sent out any email in my local environment.
我无法在本地环境中发送任何电子邮件。
I keep getting :
我不断得到:
_
_
.env file.
.env 文件。
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=*****
Note: Surprisingly - I have the same setting in my production server, and it works perfectly.
注意:令人惊讶的是 - 我在我的生产服务器中有相同的设置,它运行良好。
Any hints / suggestions ?
任何提示/建议?
回答by cyber8200
Update my driver line to
将我的驱动程序行更新为
MAIL_DRIVER=sendmail
MAIL_DRIVER=sendmail
It works on the first try.
它在第一次尝试时有效。
Final .env
file should look like this
最终.env
文件应如下所示
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=*****
回答by derdida
For me the following worked with GMAIL:
对我来说,以下与 GMAIL 一起工作:
'encryption' => 'ssl',
.env
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=xxx
回答by Junaid Masood
1: Either you must allow less secure apps or use app password by enabling 2 step verification on your gmail acc. 2: Disable any antivirus on your machine.
1:您必须允许安全性较低的应用程序或通过在您的 Gmail 帐户上启用两步验证来使用应用程序密码。2:禁用您机器上的任何防病毒软件。
回答by poonam rawal
Change setting in .env file and keep your mail server's credentials after setup of smtp
更改 .env 文件中的设置并在设置 smtp 后保留邮件服务器的凭据
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxx
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxx
回答by Kar
Laravel also includes drivers for the Mailgun and Mandrill HTTP APIs. These APIs are often simpler and quicker than the SMTP servers. Both of these drivers require that the Guzzle 5 HTTP library be installed into your application. You can add Guzzle 5 to your project by adding the following line to your composer.json file:
Laravel 还包括 Mailgun 和 Mandrill HTTP API 的驱动程序。这些 API 通常比 SMTP 服务器更简单、更快。这两个驱动程序都要求将 Guzzle 5 HTTP 库安装到您的应用程序中。您可以通过在 composer.json 文件中添加以下行来将 Guzzle 5 添加到您的项目中:
"guzzlehttp/guzzle": "~5.0"
composer update
Mailgun Driver
邮枪驱动程序
To use the Mailgun driver, set the driver option to mailgun in your config/mail.php configuration file. Next, create an config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options:
要使用 Mailgun 驱动程序,请在您的 config/mail.php 配置文件中将驱动程序选项设置为 mailgun。接下来,如果您的项目尚不存在 config/services.php 配置文件,请创建一个。验证它是否包含以下选项:
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
Mandrill Driver
山钻驱动器
To use the Mandrill driver, set the driver option to mandrill in your config/mail.php configuration file. Next, create an config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options:
要使用 Mandrill 驱动程序,请在 config/mail.php 配置文件中将驱动程序选项设置为 mandrill。接下来,如果您的项目尚不存在 config/services.php 配置文件,请创建一个。验证它是否包含以下选项:
'mandrill' => [
'secret' => 'your-mandrill-key',
],
Basic Usage
基本用法
The Mail::send method may be used to send an e-mail message:
Mail::send('emails.welcome', ['key' => 'value'], function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});