Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Laravel 5 email error handeling when username or password is wrong

$
0
0

I'm working first time on sending mail using smtp in Laravel.

I have configured my gmail details and every thing is working fine and I'm getting mail to my inbox.

But I want to know how to handle error/exception when provided gmail information like Username or Password is wrong.

Right now when I provide a wrong password it is taking me to error screen with following message:

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257 f191sm3044706pfa.26 - gsmtp"

I have tried adding some code in app\Exceptions\handler.php as below

public function render($request, Exception $e){    //This is my code    if ($e instanceof Swift_RfcComplianceException){        return redirect($request->fullUrl())->with('error',"We have issue sending you an email");    }    return parent::render($request, $e);}

My smtp details in .env file are: (Working fine)

MAIL_DRIVER=smtpMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_ADDRESS=myemail@gmail.comMAIL_NAME=Arun SinghMAIL_USERNAME=myemail@gmail.comMAIL_PASSWORD=mypassword

Code snippet for sending mail: (Working fine)

Mail::queue('/emails/test', array('firstname'=>'arun'), function($message){    $to_email = 'toemail@gmail.com';    $to_firstname = 'Sanju';    $to_lastname = 'Singh';    $message->to($to_email, $to_firstname.''.$to_lastname)->subject('Welcome to the XYZ!');})

Thank you for your help.


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>