duanmingting9544
2018-09-26 06:27
浏览 60
已采纳

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

Getting error while sending mail from a in Laravel website.

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 file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=arafat@lasermedicalbd.com
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.

How to solve it !!

图片转代码服务由CSDN问答提供 功能建议

Laravel 网站发送邮件时出错。

local.ERROR:无法与主机smtp.gmail.com建立连接[连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为 连接主机未能响应。 #10060]

.env file

  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 文件中更改( PORT DRIVER ),都会显示相同的错误。

如何解决!!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudong4532 2018-09-26 06:33
    已采纳

    clear the env file cache

    php artisan config:cache
    php artisan cache:clear
    

    configure 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'),
            ],
        ],
    
    ];
    
    已采纳该答案
    打赏 评论
  • dongzhong2008 2019-08-08 00:09

    In file 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,
         ],
    ],
    
    打赏 评论

相关推荐 更多相似问题