Skip to content

Instantly share code, notes, and snippets.

@johnkary
Created January 20, 2015 16:29
Show Gist options
  • Save johnkary/fd31583e742b0e59c463 to your computer and use it in GitHub Desktop.
Save johnkary/fd31583e742b0e59c463 to your computer and use it in GitHub Desktop.
How to customize Swift_Message creation via Monolog SwiftMailerHandler. See discussion https://github.com/Seldaek/monolog/pull/497
<?php
namespace My;
class MonologErrorEmailPrototype
{
private $fromAddress;
private $toAddress;
private $host;
private $env;
public function __construct($fromAddress, $toAddress, $host, $env)
{
$this->fromAddress = $fromAddress;
$this->toAddress = $toAddress;
$this->host = $host;
$this->env = $env;
}
public function buildMessage($content, array $records)
{
$message = new \Swift_Message();
// Do any dynamic processing right here create Swift_Message given $content and $records
$message
->setTo($this->toAddress)
->setFrom($this->fromAddress)
->setSubject($this->buildSubject())
->setContentType('text/html')
;
return $message;
}
private function buildSubject()
{
return sprintf('[%s][%s] Error Occurred', $this->host, $this->env);
}
}
services:
my_error_email_prototype:
class: My\MonologErrorEmailPrototype
arguments: ['%mailer_from_address%', '%monolog_delivery_address%', '%router.request_context.host%', '%kernel.environment%']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment