如何配置 Laravel 中的 `.env` 文件来发送邮件?

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

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]

.env 文件

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=arafat@lasermedicalbd.com
MAIL_PASSWORD=app_specific_password
MAIL_ENCRYPTION=tls

已经谷歌搜索但无法找到解决方案。 .env 文件中的任何更改(PORTDRIVER)总是显示相同的错误。

如何解决!!

清除 env 文件缓存

php artisan config:cache
php artisan cache:clear

配置mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => 'yourEmail@gmail.com', 
        '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'),
        ],
    ],
];

在文件中 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,
     ],
],