问题
I am trying to send the mail using smpt on google mail my .env file is
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MYEmailAddress
MAIL_PASSWORD=MyPassword
MAIL_ENCRYPTION=tls
and the server code is
try {
Mail::send([], [], function ($message) use ($completeView,$emailAdress) {
$message->to($emailAdress, $emailAdress)->subject("Property List");
$message->from("Myemail", "info")->setBody($completeView, 'text/html');
});
} catch (\Exception $e) {
return array([$e->getMessage(),"Myemail"]);
}
I also enable the Less secure app access in gmail and the response I get from the server is
Expected response code 250 but got code \"530\", with message \"530 5.7.1 Authentication required
回答1:
if you are using gmail address to sent mail. then you need to on less secure app.
go to https://myaccount.google.com/lesssecureapps
then allow by turning it on.
and also use php artisan config:clear
sometimes google blocks when you try to send email through some code. In that case you got a alert mail. click on that mail(Check Activity) and mark as yes (Do you recognize this activity?)
Or you can try MAIL_DRIVER=sendmail and also use php artisan config:clear
来源:https://stackoverflow.com/questions/54967886/laravel-smtp-mail