在 Laravel 5 上检查邮件是否发送成功 [英] Check mail is sent successfully or not on Laravel 5
本文介绍了在 Laravel 5 上检查邮件是否发送成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以使用这个在 Laravel5 上发送邮件的功能
I have a function that can send mail on Laravel5 using this
/**
* Send Mail from Parts Specification Form
*/
public function sendMail(Request $request) {
$data = $request->all();
$messageBody = $this->getMessageBody($data);
Mail::raw($messageBody, function ($message) {
$message->from('yourEmail@domain.com', 'Learning Laravel');
$message->to('goper.zosa@gmail.com');
$message->subject('Learning Laravel test email');
});
return redirect()->back();
}
/**
* Return message body from Parts Specification Form
* @param object $data
* @return string
*/
private function getMessageBody($data) {
$messageBody = 'dummy dummy dummy dummy';
}
并且发送成功.但是如何检查它是否已发送?喜欢
and is sent successfully. But how to check if it was sent or not? Like
if (Mail::sent == 'error') {
echo 'Mail not sent';
} else {
echo 'Mail sent successfully.';
}
我只是在猜测那个代码.
I'm just guessing that code.
推荐答案
我不完全确定这是否可行,但你可以试一试
I'm not entirely sure this would work but you can give it a shot
/**
* Send Mail from Parts Specification Form
*/
public function sendMail(Request $request) {
$data = $request->all();
$messageBody = $this->getMessageBody($data);
Mail::raw($messageBody, function ($message) {
$message->from('yourEmail@domain.com', 'Learning Laravel');
$message->to('goper.zosa@gmail.com');
$message->subject('Learning Laravel test email');
});
// check for failures
if (Mail::failures()) {
// return response showing failed emails
}
// otherwise everything is okay ...
return redirect()->back();
}
这篇关于在 Laravel 5 上检查邮件是否发送成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文