Liiva
Liiva

Reputation: 348

Unable to set content_type for native_mailer in Monolog's yaml configuration?

I'm currently trying to use Monolog to email me uncaught exceptions formatted as HTML using PHP's native mailer. I receive the emails just fine but the HTML is in plain text, it seems the content type is set to text/plain and I am unable to set the content_type to text/html via the yaml configuration.

My monolog.yaml looks like this:

monolog:
    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: ["!event"]
        console:
            type:   console
            process_psr_3_messages: false
            channels: ["!event", "!doctrine", "!console"]
        system_logger:
            type: native_mailer
            from_email: 'Some email here'
            to_email: '[email protected]'
            subject: 'Uncaught exception'
            formatter: monolog.formatter.html
            level: error
            content_type: text/html   # this is not supported?

Looking at Monolog's NativeMailerHandler, it does have a setContentType function, but how do I access this via the yaml configuration?

Upvotes: 3

Views: 231

Answers (2)

patrickj
patrickj

Reputation: 73

When using native_mailer, you can directly set the Content-Type header to achieve the desired output, since 2019.

monolog:
  handlers:
    your_handler:
      headers:
        - "Content-Type: text/html"

Upvotes: 0

Liiva
Liiva

Reputation: 348

After (unsuccessfully) trying for some time to set the content_type to html/text for the native_mailer, I just switched to the swift_mailer instead.

Upvotes: 0

Related Questions