如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:05:18  来源:igfitidea点击:

How to configure `.env` file in Laravel for sending mail?

phplaravelemailxamppgsuite

提问by lene

Getting error while sending mail from a in Laravelwebsite.

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章

.envfile

.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 .envfile always shows the same error.

已经在谷歌搜索,但还没有得到解决方案。无论我在文件中更改(PORTDRIVER.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,
     ],
],