laravel SMTP mail

风格不统一 提交于 2020-01-06 08:00:07

问题


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:


  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

  2. 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?)

  3. Or you can try MAIL_DRIVER=sendmail and also use php artisan config:clear



来源:https://stackoverflow.com/questions/54967886/laravel-smtp-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!