问题描述
我试图发送一个带有laravel 5.2的gmail。但它是抛出这个错误
在localhost中正常工作 >
这是我的 .env 文件
MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 465
[email protected]
MAIL_PASSWORD =密码
MAIL_ENCRYPTION = ssl
并且这是我的 mail.php
<?php
return [
/ *
| ------------------ -------------------------------------------------- ------
| Mail Driver
| ------------------------------------------- -------------------------------
|
| Laravel同时支持SMTP和PHP的邮件功能作为
|的驱动程序发送电子邮件。您可以在
|中指定您使用的是哪一个你的应用在这里。默认情况下,Laravel是为SMTP邮件设置的。
|
|支持:smtp,mail,sendmail,mailgun,mandrill,
| ses,sparkpost,log
|
* /
'driver'=> env('MAIL_DRIVER','smtp'),
/ *
| ------------------------ --------------------------------------------------
| SMTP主机地址
| ------------------------------------------ --------------------------------
|
|这里您可以提供您的
|使用的SMTP服务器的主机地址应用。提供了与
|兼容的默认选项Mailgun邮件服务将提供可靠的交付。
|
* /
'host'=> env('MAIL_HOST','smtp.gmail.com'),
/ *
| -------------------- -------------------------------------------------- ----
| SMTP主机端口
| ------------------------------------------ --------------------------------
|
|这是您的应用程序用于将电子邮件发送到
|的SMTP端口应用程序的用户。与主机一样,我们已将此值设置为
|在默认情况下与Mailgun电子邮件应用程序保持兼容。
|
* /
'port'=> env('MAIL_PORT',465),
/ *
| -------------------------- ------------------------------------------------
| GlobalFromAddress
| ---------------------------------------- ----------------------------------
|
|您可能希望您的应用程序发送的所有电子邮件都是从
|发送的相同的地址。在这里,您可以指定一个名称和地址是
|全球范围内用于您的应用程序发送的所有电子邮件。
|
* /
'from'=> ['address'=> '','name'=> ''],
/ *
| ------------------------------- -------------------------------------------
|电子邮件加密协议
| ---------------------------------------- ----------------------------------
|
|在这里你可以指定
|应该使用的加密协议应用程序发送电子邮件。一个合理的默认使用
|传输层安全协议应该提供很高的安全性。
|
* /
'encryption'=> env('MAIL_ENCRYPTION','ssl'),
/ *
| ------------------------ --------------------------------------------------
| SMTP服务器用户名
| ------------------------------------------ --------------------------------
|
|如果您的SMTP服务器需要用户名进行身份验证,您应该
|放在这里。这将用于
|上的服务器验证连接。您也可以在此之下设置密码值。
|
* /
'username'=> env('MAIL_USERNAME'),
/ *
| ---------------------------- ----------------------------------------------
| SMTP服务器密码
| ------------------------------------------ --------------------------------
|
|在这里,您可以设置您的SMTP服务器发送
|所需的密码来自应用程序的消息。这将通过
|给予服务器连接,以便应用程序能够发送消息。
|
* /
'password'=> env('MAIL_PASSWORD'),
/ *
| -------- -------------------------------------------------- ----------------
| Sendmail系统路径
| ------------------------------------------ --------------------------------
|
|当使用sendmail驱动程序发送电子邮件时,我们需要知道
| Sendmail位于此服务器上的路径。默认路径有
|在这里提供,这将在大多数系统上运行良好。
|
* /
'sendmail'=> '/ usr / sbin / sendmail -bs',
];
1:您必须允许安全性较低的应用或使用通过在您的gmail acc上启用2步验证来启用应用程序密码。
2:在您的计算机上禁用任何防病毒软件(这是没有人会告诉您的,但在很多情况下是必需的)。
3:不要忘记清除缓存(有时它不会从.env文件中获取更新的内容)
4:你不需要改变配置目录下的Mailer中的任何东西(不推荐),你应该使用env变量
I am trying to send an gmail with laravel 5.2. But it is throwing this error
it work fine in localhost
this my .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
and this my mail.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill",
| "ses", "sparkpost", "log"
|
*/
'driver' => env('MAIL_DRIVER', 'smtp'),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 465),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => '', 'name' => ''],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' =>env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',
];
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(this is something no one will tell u but is necessary in many cases).
3: Don't forget to clear your cache (sometimes it don't take updated content from .env file)
4: You don't need to change anything in Mailer inside config directory(not recommended), you should use env variables
这篇关于无法与主机smtp.gmail.com建立连接[Laravel 5.2中的连接超时#110]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!