问题
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.
Here's my Swift Mailer configuration, in which I'd like to send errors using the "phpmail" mailer:
Swiftmailer Configuration
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 }
And the relevant part of my Monolog configuration:
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
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!
回答1:
If you looked into the source code of \Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension, you find there all monolog definitions.
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']
));
Are you sure that your phpmail is working correctly?
来源:https://stackoverflow.com/questions/32461962/how-to-configure-monolog-to-send-errors-via-swiftmailer-to-alternate-mailer-in-s