[英]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个错误
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]
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. 这就是我所做的。
I enabled two step verification on may gmail account 我对5月的Gmail帐户启用了两步验证
created separate apps password for my app here (screenshot below) ( https://security.google.com/settings/security/apppasswords ) 在此处为我的应用创建了单独的应用密码(以下屏幕截图)( https://security.google.com/settings/security/apppasswords )
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.