I'm trying to send an email to a specified user by typing in the URL, but I'm getting the following error:
Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
So far I'm just trying to get it to work with Gmail. How can I get this to work?
This is what I have so far: mail.php
<?php
return [
'driver' => env('MAIL_DRIVER',' smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' =>"MyUsername@gmail.com" , 'name' => "example"],
'encryption' => 'tls',
'username' => env('MyUsername@gmail.com'),
'password' => env('MyPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
This is what I have in the routes:
Route::get('test', function() {
Mail::send('Email.test', [], function ($message) {
$message->to('example@gmail.com', 'HisName')->subject('Welcome!');
});
});
This is what I have in my controller:
class MailController extends Controller
{
public function Sending_Email()
{
$this->call('GET','Email.test');
return View('Email.test');
}
}
And this is what is in my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername@gmail.com
MAIL_PASSWORD=MyPassword
the problem will be solved by clearing cache
That simply means that your server does not have access to the SMTP Server.
You can test this by doing:
You should get the Access denied error.
The solution is to just use another SMTP server that can be accessed by your server.
I had the same problem as you, I just got it to work.
Firstly, you need to double check that the .env settings are set up correctly. Here are my settings:
Please make sure that your password is not between quotes :).
And in config/mail.php it has the following, without the comments.
Hope it works for you :)
I know it's working for you now @Vantheman6 but this is what worked for me in case it's the same for someone else.
I added to my .env file the details of the mail service I am using. So make sure the following details
in the .env file are accurate.
NOTE: Don't forget to restart your server after editing the .env file so it will pick the new data that you put in there.
If you don't restart your server, the .env file will still continue to present the old mail data to the app even though you have made changes which can cause this error.
For future reference to people who come here. after you run the command that was given in the third answer here(I am using now Laravel 5.3).
You may encounter this problem:
In that case, you need to add it back manually to your provider list under the app.php file. GO-TO:
app->config->app.php->'providers[]'
and add it, like so:Hope That helps someone.