Laravel 5.4 使用 gmail 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45150059/
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
Laravel 5.4 send Email with gmail
提问by dwdawdawdaw
I'm trying to send Emails from google but couln't make it yet. I did everything I've found by searching through google but it still won't work.
我正在尝试从谷歌发送电子邮件,但还没有成功。我通过谷歌搜索做了所有我发现的事情,但它仍然不起作用。
My Mail.php
我的邮件.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'blablabla'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
my .env:
我的.env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
I also allowed "Less secure Apps" on the gmail settings.
我还允许在 gmail 设置中使用“安全性较低的应用程序”。
The Mail-Code works perfect, I've tried it out before on mailtrap.io. But if I change it to google I only get errors.
Mail-Code 工作完美,我之前在 mailtrap.io 上试过。但是如果我把它改成谷歌,我只会得到错误。
Thats my Code for sending Mail:
那是我发送邮件的代码:
\Mail::to('[email protected]')->send(new NewThread($thread));
And thats the error:
这就是错误:
(1/1) ErrorException
(1/1) 错误异常
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
Can someone help me there?
有人可以帮助我吗?
回答by tompec
Try this, it works for me:
试试这个,它对我有用:
MAIL_PORT=465
MAIL_ENCRYPTION="ssl"
Also make sure to generate an app password if you're using 2FA.
如果您使用的是 2FA,请确保生成应用密码。
回答by verax
Don't use TLS or SSL then.
那就不要使用 TLS 或 SSL。
MAIL_ENCRYPTION=tls
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
Change both to:
将两者更改为:
MAIL_ENCRYPTION=
'encryption' => env('MAIL_ENCRYPTION', ''),
Then run:
然后运行:
php artisan config:clear
This should do the job
这应该可以胜任