“Laravel 邮件验证错误 SMTP 550。如何处理此错误?”

huangapple go评论69阅读模式
英文:

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

问题

用户已注册,并发送邮件确认帐户。

响应代码为250,但得到代码为550,邮箱无效。同时,Web服务器出现错误500,“Laravel 邮件验证错误 SMTP 550。如何处理此错误?”

如何处理此错误并向用户显示其电子邮件不存在?

我的.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}"

我理解这是一个SMTP服务器错误。确实,该邮箱不存在。如何向用户报告此错误(处理错误)?目前,在执行此操作时,Laravel返回500错误。

英文:

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 server“Laravel 邮件验证错误 SMTP 550。如何处理此错误?”

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

答案1

得分: 0

在app/Exceptions/Handler.php中添加以下函数:

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

然后在resources/views/errors/目录下添加550.blade.php视图文件,其中包含您的错误文本和向用户显示的文本。

然后大家都开心

英文:

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

huangapple
  • 本文由 发表于 2023年5月14日 23:26:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定