Laravel Gmail Configuration Error

2019-03-03 15:32发布

问题:

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'