Reputation: 5310
I'm getting the following error trying to send mail from localhost using 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
[email protected]
MAIL_PASSWORD=11111111
MAIL_ENCRYPTION=ssl
[email protected]
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' => '[email protected]',
'name' => 'MY.NAME',
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('[email protected]'),
'password' => env('11111111'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
Tried: changing ports, encryption, clearing cache, restarting server in all possible combinations. :) As I see it there's one more parameter I need to pass to the mailer library. Some thing like
auth_mode=login_first
Can this be done through laravel settings?
Upvotes: 2
Views: 6654
Reputation: 5310
I'm posting my working settings. You've got to check how laravel env
helper function is used in your config file. Also when using smtp.yandex.com auth email and form email must match.
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
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','[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,
];
Controller function
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.');
}
Upvotes: 1