gpt4 book ai didi

laravel - 在 Laravel 5 上检查邮件是否发送成功

转载 作者:行者123 更新时间:2023-12-02 09:20:01 26 4
gpt4 key购买 nike

我有一个功能,可以使用它在 Laravel5 上发送邮件

/**
* 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';
}

并已成功发送。但如何查看是否已发送呢?喜欢

if (Mail::sent == 'error') {
echo 'Mail not sent';
} else {
echo 'Mail sent successfully.';
}

我只是猜测该代码。

最佳答案

我不完全确定这会起作用,但你可以尝试一下

/**
* 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 - 在 Laravel 5 上检查邮件是否发送成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32882357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com