2017-02-24 67 views
1

我收到以下错误试图从本地主机使用SMTP发送邮件:Laravel 5.4 SMTP错误 “发送AUTH命令第一”

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 
[email protected] 
MAIL_PASSWORD=11111111 
MAIL_ENCRYPTION=ssl 
[email protected] 
MAIL_NAME=MY.NAME 

配置/ mail.php

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

尝试过:ch老化端口,加密,清除缓存,以所有可能的组合重新启动服务器。 :) 正如我所见,还有一个参数需要传递给邮件程序库。有些东西就像

auth_mode=login_first 

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

+0

您可能会更改为MAIL_ENCRYPTION = null。但后来我得到了'预期的响应代码250,但得到了代码“”,并带有消息“”' 对于开发也可以考虑使用[漂亮和免费的邮件捕获器](https://mailtrap.io/)。并且不要忘记清除配置缓存'php artisan config:cache' –

+0

我尽量不设置加密,但它没有帮助。另外,我认为这个特殊的smtp服务器需要ssl。在过去的几个小时里,我尝试了mailgun,mandrill,sparkpost,并且只得到更多的错误。这不应该是困难的,对吧​​? :) – sr9yar

回答

1

我张贴我的工作设置。您必须检查配置文件中如何使用辅助函数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 
[email protected] 
MAIL_PASSWORD=123123123 
MAIL_ENCRYPTION=ssl 
[email protected] 
MAIL_NAME=MY.NAME 

配置/ 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','[email protected]'), 
     'name' => env('MAIL_NAME','MY.NAME'), 
    ], 
    'encryption' => env('MAIL_ENCRYPTION', 'ssl'), 
    'username' => env('MAIL_USERNAME','[email protected]'), 
    '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.'); 
}