Created
January 20, 2015 16:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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