简体   繁体   English

无法与主机smtp.gmail.com建立连接

[英]Connection could not be established with host smtp.gmail.com Laravel

I am trying to send a mail to my email-id. 我正在尝试向我的电子邮件ID发送邮件。 I have followed all the steps that might required to send a mail. 我已经完成了发送邮件可能需要的所有步骤。

But it keeps on coming 2 errors 但它继续出现2个错误

  1. Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.#10060] 无法与主机smtp.gmail.com建立连接[连接尝试失败,因为在一段时间后被连接方未正确响应,或者由于连接主机未能响应而建立的连接失败。#10060]

  2. Maximum execution time of 30 seconds exceeded. 超过30秒的最大执行时间。

my controller is 我的控制器是

public function contact()
    {
   Mail::send('clientinfo.contact',['name' => 'shweta'],function($message){
            $message->to('myemail@gmail.com','Some Name')->subject('Welcome!')->from('otheremail@example.com');
           });

mail.php file : mail.php文件:

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'someone@example.com', 'name' => 'Some  One Sender'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
 'pretend' => false,

];

Please help me through this. 请帮助我。

Make sure you install Guzzle to your project by adding the following line to your composer.json file: 通过将以下行添加到composer.json文件中,确保将Guzzle安装到项目中:

"guzzlehttp/guzzle": "~5.3|~6.0" “ guzzlehttp / guzzle”:“〜5.3 |〜6.0”

and editing your .env file with real email-id and password. 并使用真实的电子邮件ID和密码来编辑.env文件。 Also, enable, less secure apps for that email-id as told by @Bharat Geleda 此外,按照@Bharat Geleda的指示,为该电子邮件ID启用安全性较低的应用

then your above code will run properly. 那么您的上述代码即可正常运行。

This is what I did. 这就是我所做的。

  1. I enabled two step verification on may gmail account 我对5月的Gmail帐户启用了两步验证

  2. created separate apps password for my app here (screenshot below) ( https://security.google.com/settings/security/apppasswords ) 在此处为我的应用创建了单独的应用密码(以下屏幕截图)( https://security.google.com/settings/security/apppasswords

  3. I that password into my laravel .env file and it worked. 我将该密码输入到我的laravel .env文件中,它可以正常工作。

screenshot just select "Other(custom name)" on the "select app" and it will generate a password for you. 屏幕快照只需在“选择应用程序”上选择“其他(自定义名称)”,它将为您生成密码。

在此处输入图片说明

使用MAIL_PORT=587代替.env文件中的默认mail_port。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows 7中无法使用主机smtp.gmail.com建立Laravel 5连接 - Laravel 5 Connection could not be established with host smtp.gmail.com in windows 7 无法与主机smtp.gmail.com [#0]建立连接 - Connection could not be established with host smtp.gmail.com [ #0] 无法与SwiftMailer中的主机smtp.gmail.com [#0]建立连接 - Connection could not be established with host smtp.gmail.com [#0] in SwiftMailer 无法与主机 smtp.gmail.com 建立连接 - Connection could not be established with host smtp.gmail.com Laravel 无法与主机 smtp.gmail.Z4D236D9A2D102C5FE6AD1C50DACEC 建立 - Laravel could not be established with host smtp.gmail.com [on hold] 无法在 laravel 5.6 电子邮件发送中与主机 smtp.gmail.com [连接被拒绝 #111] 建立连接 - Connection could not be established with host smtp.gmail.com [Connection refused #111] in laravel 5.6 email send 无法在laravel 5.2中与主机smtp.gmail.com建立连接[连接超时#110] - Connection could not be established with host smtp.gmail.com [Connection timed out #110] in laravel 5.2 Php Laravel 5.1-无法与主机smtp.gmail.com建立连接[连接被拒绝#111] - Php Laravel 5.1- Connection could not be established with host smtp.gmail.com [Connection refused #111] Laravel:Swift_TransportException无法与主机smtp.gmail.com建立连接 - Laravel : Swift_TransportException Connection could not be established with host smtp.gmail.com 无法与主机smtp一起建立连接Laravel电子邮件中网络无法访问#101错误 - Connection could not be established with host smtp.gmail.com Network is unreachable #101 error in Laravel email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM