duanquan4451 2018-11-18 15:27
浏览 75

Laravel电子邮件记录通道

I have a Laravel 5.6 project and I want to configure it such that high level errors are emailed to me. I have added an email channel to logging.php config file and specified Monolog's Swiftmailer as the handler but since it needs a mailer instance and message in its constructor I don't know what values should be supplied. Any help is much appreciated.

PS: I do know there are packages for this purpose but think this should be simple enough to do manually.

'email' => [
    'driver' => 'monolog',
    'handler' => Monolog\Handler\SwiftMailerHandler::class,
    'handler_with' => [
        'mailer' => ?,
        'message' => ?,
    ],
],
  • 写回答

1条回答 默认 最新

  • duanbei3704 2019-04-07 20:50
    关注

    It might be a little late but from Symfony SwiftMailer documentation you should use something like this:

    ...
    'email' => [
        'driver' => 'monolog',
        'level' => 'critical',
        'handler' => SwiftMailerHandler::class,
        'handler_with' => [
            'mailer' => (new Swift_SmtpTransport(env('MAIL_HOST'), env('MAIL_PORT'), env('MAIL_ENCRYPTION')))
                ->setUsername(env('MAIL_USERNAME'))
                ->setPassword(env('MAIL_PASSWORD')),
            'message' => (new Swift_Message('[LOG] Exception'))
                ->setFrom([env('LOG_MAIL_FROM_ADDRESS') => env('LOG_MAIL_FROM_NAME')])
                ->setTo([env('LOG_MAIL_TO_ADDRESS') => 'Dev'])
                ->setBody('Here is the message itself')
    
        ],
        'formatter' => HtmlFormatter::class,
    ],
    ...
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog