0

Due to depreciation, I'm converting my Monolog email logging from Swiftmailer to Symfony Mailer (as recommended here).

I have successfully completed the conversion and am receiving the emails.

However, with Swift Mailer all Monolog emails were nicely formatted (see example). With Symfony Mailer, I only have a text version of the email.

Is there a way to get similar HTML output with Symfony Mailer?

By the way, I'm only using "symfony/mailer" and "symfony/monolog-bridge", not the full framework

My code:

$logger = new Logger('My Logger');

$transport = Transport::fromDsn('MYDSN');
$mailer = new Mailer($transport);

$message = (new Email())
    ->from(new Address('from@example.com', 'John Doe'))
    ->to(new Address('to@example.com', 'Jane Doe'))
    ->subject('My Subject');

$logger->pushHandler(
    new MailerHandler(
        $mailer,
        $message,
        Logger::ERROR
    )
);
GlennM
  • 300
  • 1
  • 14

1 Answers1

0

Got it working, I had to add an HtmlFormatter (this was not necessary with Swift Mailer):

$logger->pushHandler(
    (new MailerHandler(
        $mailer,
        $message,
        Logger::ERROR
    )->setFormatter(new HtmlFormatter())
);
GlennM
  • 300
  • 1
  • 14