Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,6 +100,17 @@ public function setTemplate($templateName, array $vars = array())
$this->getMessage()->setReplyTo($template->renderBlock('reply_to', $vars));
}

if ($template->hasBlock('cid')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce que on pourrais pas faire un truc plus sympa avec une fonction twig {{ image_cid('url') }}

$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;
}

Expand Down