如何在 Laravel 中配置 `.env` 文件以发送邮件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52511262/
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
How to configure `.env` file in Laravel for sending mail?
提问by lene
Getting error while sending mail from a in Laravel
website.
从Laravel
网站发送邮件时出错。
local.ERROR: 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]
local.ERROR: 无法与主机 smtp.gmail.com 建立连接 [连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应而建立连接失败。第10060章
.env
file
.env
文件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=app_specific_password
MAIL_ENCRYPTION=tls
Already googling but can't get the solution yet. Whatever I change( PORT
, DRIVER
) in .env
file always shows the same error.
已经在谷歌搜索,但还没有得到解决方案。无论我在文件中更改(PORT
,DRIVER
).env
总是显示相同的错误。
How to solve it !!
怎么解决啊!!
回答by Rp9
clear the env file cache
清除 env 文件缓存
php artisan config:cache
php artisan cache:clear
configure mail.php
配置mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Your Title'],
'encryption' => 'tls',
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
回答by fcva
In file mail.php
在文件 mail.php 中
//In Markdown Mail Settings, add
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'stream' => [
'ssl'=> [
'verify_peer'=>false,
'verify_peer_name'=>false,
'allow_self_signed'=>true,
],
],