Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当用户名或密码错误时,处理Laravel 5电子邮件错误_Php_Email_Laravel 5_Smtp - Fatal编程技术网

Php 当用户名或密码错误时,处理Laravel 5电子邮件错误

Php 当用户名或密码错误时,处理Laravel 5电子邮件错误,php,email,laravel-5,smtp,Php,Email,Laravel 5,Smtp,我第一次在Laravel使用smtp发送邮件 我已经配置了我的gmail详细信息,一切正常,我正在将邮件发送到我的收件箱 但我想知道当gmail提供的用户名或密码等信息错误时,如何处理错误/异常 现在,当我提供错误的密码时,我将进入错误屏幕,并显示以下消息: Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "535", with mess

我第一次在Laravel使用smtp发送邮件

我已经配置了我的gmail详细信息,一切正常,我正在将邮件发送到我的收件箱

但我想知道当gmail提供的用户名或密码等信息错误时,如何处理错误/异常

现在,当我提供错误的密码时,我将进入错误屏幕,并显示以下消息:

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"
我尝试在app\Exceptions\handler.php中添加一些代码,如下所示

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);
}
我在.env文件中的smtp详细信息如下:(工作正常)

用于发送邮件的代码段:(工作正常)


感谢您的帮助。

在错误处理程序中,您试图捕获的异常是

Swift_RfcComplianceException
但是抛出的异常是

Swift_TransportException
要捕获传输异常,只需将其添加到错误处理程序:

if ($e instanceof \Swift_TransportException){
    return redirect($request->fullUrl())->with('error',"We have issue sending you an email");
}
在my.env文件中

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME= angambameetei93@gmail.com
MAIL_PASSWORD= xxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
我也犯了同样的错误,但过了很长一段时间后,我用

https://myaccount.google.com/lesssecureapps
在此,必须启用不太安全的应用程序访问

Allow less secure apps: ON

谢谢。

如果您想处理
Swift\u TransportException
您应该在自定义异常渲染器中检查
If($e instanceof Swift\u TransportException)
,谢谢。您能告诉我如何读取要显示给最终用户的异常消息吗?是的,您可以使用异常对象的getMessage函数访问异常消息:
$e->getMessage()
是的,我现在可以读取消息,但它仍然表示对非对象的成员函数调用send()。现在来解决这个问题。我正在尝试这样做:
$status=Mail::queue('/emails/test',array('firstname'=>'arun'),function($message){$to_email='arunsingh0430@gmail.com“;$to_firstname='Arun';$to_lastname='Singh';$message->to($to_email,$to_firstname.'”。$to_lastname)->主题('Welcome to the Adelphi!'););echo$状态谢谢,成功了。你能告诉我如何读取异常消息以显示给最终用户吗?太棒了,如果你想使用异常给你的消息,你可以这样做:
return redirect($request->fullUrl())->with('error',$e->getMessage())谢谢你的回复。请告诉我如何在mail函数中访问
$to_email
$to_firstname
$to_lastname
变量。对于以下代码,未识别变量,并引发错误<代码>$to_email='to_email@gmail.com'; $to_firstname='Arun'$to_lastname='Singh';邮件::队列('/emails/test',数组('firstname'=>'arun'),函数($message){$message->to($to_email,$to_firstname.'''.$to_lastname)->主题('Welcome'.$to_firstname.'to XYZ!')我正在从dbI获取这些变量。我不完全确定邮件变量是如何工作的,请仔细查看,可能会有一些有用的提示。
https://myaccount.google.com/lesssecureapps
Allow less secure apps: ON