如何配置 Monolog 以通过 SwiftMailer 将错误发送到 Symfony2 中的备用邮件程序 [英] How to configure Monolog to send errors via SwiftMailer to alternate mailer in Symfony2

查看:22
本文介绍了如何配置 Monolog 以通过 SwiftMailer 将错误发送到 Symfony2 中的备用邮件程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 symfony2 应用程序中,我有两个邮件程序,我想使用非默认邮件程序来发送 Monolog 错误.现在正在按预期发送错误,但我无法将其发送到非默认邮件程序.

In my symfony2 application I have two mailers, and I'd like to use the non-default mailer to send monolog errors. Errors are being sent as expected now, but I can't get it to send to the non default mailer.

这是我的 Swift Mailer 配置,我想在其中使用phpmail"邮件程序发送错误:

Here's my Swift Mailer configuration, in which I'd like to send errors using the "phpmail" mailer:

default_mailer: authsmtp

mailers:
    authsmtp:
        transport: %mailer_transport%
        host:      %mailer_host%
        username:  %mailer_user%
        password:  %mailer_password%
        port:      %mailer_port%
        spool:     { type: memory }

    phpmail:
        transport: smtp
        host:      127.0.0.1
        spool:     { type: memory }

以及我的 Monolog 配置的相关部分:

handlers:

    mail_on_errors:
        type:         fingers_crossed
        action_level: critical
        handler: buffered

    buffered:
        type:    buffer
        handler: swift

    swift:
        type:       swift_mailer
        mailer:     swiftmailer.mailer.phpmail
        from_email: %from_email_address%
        to_email:   [ %errors_receiving_address% ]
        subject:    An Error Occurred!
        level:      debug

你可以看到我试图通过将mailer: swiftmailer.mailer.phpmail"添加到 swift monolog 处理程序来让它工作——这不在文档中(我可以找到)所以我刚刚编造出来的,它没有出错,但它也没有使用 phpmail 处理程序.

You can see I tried to get this to work by adding "mailer: swiftmailer.mailer.phpmail" to the swift monolog handler----this isn't covered in the docs (that i can find anyway) so I just made this up, and it doesn't error out, but it also doesn't use the phpmail handler.

如果有人知道正确的配置以使其正常工作,我将不胜感激!

If anyone knows the proper configuration to get this to work I'd appreciate it!

推荐答案

如果你查看了 \Symfony\Bundle\MonologBu​​ndle\DependencyInjection\MonologExtension,你可以在那里找到所有的 Monolog 定义.

If you looked into the source code of \Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension, you find there all monolog definitions.

swift_mailer 处理程序允许您通过设置mailer"键(如您所料)来定义自定义邮件程序.

swift_mailer handler allows you to define a custom mailer by setting "mailer" key (as you guessed).

$messageFactory->setArguments(array(
    new Reference($handler['mailer']),
    $handler['from_email'],
    $handler['to_email'],
    $handler['subject'],
    $handler['content_type']
));

您确定您的 phpmail 工作正常吗?

Are you sure that your phpmail is working correctly?

这篇关于如何配置 Monolog 以通过 SwiftMailer 将错误发送到 Symfony2 中的备用邮件程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆