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

时间:2018-09-26 06:27:37

标签: php laravel email xampp gsuite

Laravel网站发送邮件时出错。

  

local.ERROR:无法与主机smtp.gmail.com建立连接[连接尝试失败,因为一段时间后被连接方未正确响应,或者由于连接主机未能响应而建立连接失败。 #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

已经进行了谷歌搜索,但仍无法解决。无论我在PORT文件中进行的更改(DRIVER.env)总是显示相同的错误。

如何解决!!

2 个答案:

答案 0 :(得分:1)

清除环境文件缓存

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'),
        ],
    ],

];

答案 1 :(得分:0)

在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,
     ],
],