Laravel Gmail Configuration Error

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 16:53:31

问题


I have been having this issue with Laravel email with Gmail and I have checked and reviewed so many questions on Stack Overflow but none still works in my case. I am using Laravel 5.4 and Xampp.

At first I thought it was my Xampp that cannot allow sending the emails but also when I move to the live mode(hosted it on a shared hosting) still have same issues there as well

But whenever I set the configuration to use Mailtrap, it's working and I know mailtap is just a development mail server, but whenever I use the Gmail it give me error such as "Expected response code 220 but got code "", with message """

Also when I try it on live mode it still gives same error.

My configuration file has the following

.env

MAIL_DRIVER=smtp
MAIL_HOST=gmail-smtp-msa.l.google.com (also tried smtp.gmail.com)
MAIL_PORT=587
MAIL_USERNAME=email@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

mail.php

<?php

return [


    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'gmail-smtp-msa.l.google.com'),


    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => 'email@gmail.com',
        'name' => 'Name Here',
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

     'username' => env('MAIL_USERNAME', 'email@gmail.com'),

    'password' => env('MAIL_PASSWORD', 'password'),



    'sendmail' => '/usr/sbin/sendmail -bs',
    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

回答1:


As well as the configuration on the Laravel side, you need to enable "Less secure apps" in your Gmail account.

On the Laravel side, this guide shows the settings you need. Use smtp.gmail.com for host, and either 465/ssl or 587/tls.




回答2:


Hey here is the solution

MAIL_DRIVER='smtp

MAIL_HOST='smtp.gmail.com'

MAIL_PORT=587

MAIL_USERNAME='sample@gmail.com'

MAIL_FROM_ADDRESS='sample@gmail.com'

MAIL_FROM_NAME='Some Name'

MAIL_PASSWORD='XXXXX'

MAIL_ENCRYPTION='tls'



来源:https://stackoverflow.com/questions/46318466/laravel-gmail-configuration-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!