预期的响应代码为250,但代码为“ 530”,消息为“ 530-5.5.1,需要身份验证-Laravel

时间:2018-06-21 10:18:28

标签: php laravel authentication gmail

我在Laravel应用中对我的gmail帐户进行身份验证时遇到问题。

我尝试使用ssl(端口:465)和tls(端口:587),但仍然无法正常工作。

这是我的.env文件和config / mail.php文件。请帮帮我

config / mail.php文件:

<?php

return [

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

'host' => env('MAIL_HOST', 'ssl://smtp.gmail.com'),

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

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'EMAIL_ADDRESS'),
    'name' => env('MAIL_FROM_NAME', 'NAME'),
],

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

'username' => env('username'),

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

'sendmail' => '/usr/sbin/sendmail -bs',

'markdown' => [
    'theme' => 'default',

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

];

.env文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=****@gmail.com
MAIL_PASSWORD="****"
MAIL_ENCRYPTION=ssl

谢谢!

1 个答案:

答案 0 :(得分:1)

首先要使用 .env 文件或 mail.php 如果 .env 文件使用此

    return [

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

    'host' => env('MAIL_HOST', 'ssl://smtp.gmail.com'),

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

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'oleksandr.maslyennikov@gmail.com'),
        'name' => env('MAIL_FROM_NAME', 'oleksandr'),
    ],

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

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

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

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

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

    ];

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=****@gmail.com
MAIL_PASSWORD="****"
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=oleksandr.maslyennikov@gmail.com
MAIL_FROM_NAME=oleksandr

,如果您要使用 mail.php 文件,则使用此类文件不要混淆两个文件

return [

        'driver' => 'smtp',

        'host' => 'ssl://smtp.gmail.com',

        'port' => 465,

        'from' => [
            'address' => 'oleksandr.maslyennikov@gmail.com',
            'name' => 'oleksandr',
        ],

        'encryption' => 'ssl',

        'username' => 'oleksandr.maslyennikov@gmail.com',

        'password' => 'Sobranie14@',

        'sendmail' => '/usr/sbin/sendmail -bs',

        'markdown' => [
            'theme' => 'default',

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

        ];