Search code examples
phplaravelemailsmtp

laravel verify emaIl error smtp 550. how to handle this error?


the user is registered and mail is sent to confirm the account

response code 250, but got code 550 invalid mailbox and i have error 500 with web servererror laravel

how to handle this error and show the user that his email does not exist?

part of my .env

MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.dmd120.com
MAIL_PORT=465
MAIL_USERNAME=noreply@dmd120.com
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=noreply@dmd120.com
MAIL_FROM_NAME="${APP_NAME}"

I understand that this is an smtp server error. And indeed this mailbox does not exist. How do I report this to the user (handle the error)? now, when performing this action, laravel issues error 500


Solution

  • I tell you how to handle the error, I found the solution myself:

    in app/Exceptions/Handler.php add function

    public function render($request, Throwable $e)
    {
        if ($e instanceof TransportException){
            return response()->view('errors.550',[],550);
        }
        return parent::render($request, $e); 
    }
    

    add view resources/views/errors/550.blade.php with you text error and text to user

    and everyone is happy