【问题标题】:Laravel 5.5 - Mailgun catch email errorsLaravel 5.5 - Mailgun 捕获电子邮件错误
【发布时间】:2018-03-21 03:00:36
【问题描述】:

我正在通过 Mailgun 从这样的 Laravel 5.5 应用程序发送电子邮件...

    Mail::send('emails.sendmessage', $data, function($message) use ($data) {
        $message->to($data['email']);
        $message->from('me@example.com.com', 'Ueer');
        $message->subject('Sample Email');
    });

    /* Return Success Response */
    return Response::json(array(
        'error' => false,
        'status_code' => 200,
        'response' => 'success',
    ));

如何使用此代码捕获 Mailgun 错误?有时 MailGun 会返回错误消息,如果发生这种情况,我想返回不同的响应

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    你可以看看这个问题:Laravel 5 - How Do You Catch an Mail::send() Error?

    添加 try and catch 应该可以解决问题。

    如果您出于某种原因不想添加 try/catch,我建议您预先验证每个容易从 Mail::send 抛出错误的参数

    【讨论】:

    • 当我在 try-catch 结构中添加反斜杠时,我可以处理错误:try{ ... } catch (\Exception $e) { ... }
    猜你喜欢
    • 2018-06-17
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 2018-07-29
    • 2014-04-14
    • 1970-01-01
    • 2019-10-18
    相关资源
    最近更新 更多