diff --git a/Mailer/Mailer.php b/Mailer/Mailer.php index 7175f67..001cbd1 100644 --- a/Mailer/Mailer.php +++ b/Mailer/Mailer.php @@ -11,7 +11,10 @@ class Mailer private $message; private $options; - public function __construct(\Swift_Mailer $swift, \Twig_Environment $twig, $from, $replyTo, array $options) + /** + * $twig : Twig_Environment or \Twig\Environment + */ + public function __construct(\Swift_Mailer $swift, $twig, $from, $replyTo, array $options) { $this->swift = $swift; $this->twig = $twig; @@ -97,6 +100,17 @@ public function setTemplate($templateName, array $vars = array()) $this->getMessage()->setReplyTo($template->renderBlock('reply_to', $vars)); } + if ($template->hasBlock('cid')) { + $body = $template->renderBlock('body', $vars); + $cids = explode(',', $template->renderBlock('cid', $vars)); + foreach ($cids as $key=>$cid) { + $img_data = file_get_contents($cid); + $cidToEmbed = $this->getMessage()->embed(\Swift_Image::newInstance($img_data, $key.'.png', mime_content_type($cid))); + $body = str_replace("{cid}[" . $key . "]", $cidToEmbed, $body); + } + $this->getMessage()->setBody($body, 'text/html'); + } + return $this; }