Laravel 5.4 SMTP 错误 "send AUTH command first"

Laravel 5.4 SMTP error "send AUTH command first"

我在尝试使用 smtp 从本地主机发送邮件时遇到以下错误:

Expected response code 250 but got code "503", with message "503 5.5.4 Error: send AUTH command first. "

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.com
MAIL_PORT=465
MAIL_USERNAME=robot@domain.com
MAIL_PASSWORD=11111111
MAIL_ENCRYPTION=ssl
MAIL_FROM=robot@domain.com
MAIL_NAME=MY.NAME

config/mail.php

 <?php
    return [
        'driver' => env('MAIL_DRIVER', 'smtp'),
        'host' => env('MAIL_HOST', 'smtp.yandex.com'),
        'port' => env('MAIL_PORT', 465),
        'from' => [
            'address' => 'robot@domain.com',
            'name' => 'MY.NAME',
        ],
        'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
        'username' => env('robot@domain.com'),
        'password' => env('11111111'),
        'sendmail' => '/usr/sbin/sendmail -bs',
    ];

已尝试:更改端口、加密、清除缓存、重新启动服务器的所有可能组合。 :) 如我所见,我还需要将一个参数传递给邮件程序库。像

这样的东西
auth_mode=login_first

这可以通过 laravel 设置完成吗?

我正在发布我的工作设置。您必须检查配置文件中如何使用 laravel env 辅助函数。此外,当使用 smtp.yandex.com 时,身份验证电子邮件和表单电子邮件必须匹配。

Laravel Docs for env()

The env function gets the value of an environment variable or returns a default value:

$env = env('APP_ENV');

// Return a default value if the variable doesn't exist...

$env = env('APP_ENV', 'production');

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.com
MAIL_PORT=465
MAIL_USERNAME=robot@mydomain.com
MAIL_PASSWORD=123123123
MAIL_ENCRYPTION=ssl
MAIL_FROM=robot@mydomain.com
MAIL_NAME=MY.NAME

config/mail.php

<?php
return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.yandex.com'),
    'port' => env('MAIL_PORT', 465),
    'from' => [
        'address' =>  env('MAIL_FROM','robot@mydomain.com'),
        'name' =>  env('MAIL_NAME','MY.NAME'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
    'username' => env('MAIL_USERNAME','robot@mydomain.com'),
    'password' => env('MAIL_PASSWORD','123123123'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
];

控制器功能

public function testmail()
{
    $user =  Auth::user();
    $pathToLogo = config('app.url').'/images/logo/logo_250.png';
    Mail::send('emails.testmail', array('user' => $user, 'pathToLogo' => $pathToLogo), function($message) use ($user)
        {
          $message->to($user->email);
          $message->subject('Test message');
        });
    return redirect()->route('home')->with('message','Test message sent.');
}