Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Add a callback parameter
Browse files Browse the repository at this point in the history
Allow to modify the mail before it is sent.
  • Loading branch information
jvasseur committed Mar 9, 2016
1 parent 7ec263b commit 5b9b176
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig)
/**
* @param string $name
* @param array $context
* @param callable|null $callback a callback to modify the mail before it is sent.
*/
public function send($name, array $context = [])
public function send($name, array $context = [], callable $callback = null)
{
$template = $this->twig->loadTemplate($name);

Expand Down Expand Up @@ -56,6 +57,10 @@ public function send($name, array $context = [])
$mail->setBody($blocks['body_html'], 'text/html');
}

if ($callback) {
$callback($mail);
}

$this->mailer->send($mail);
}

Expand Down

0 comments on commit 5b9b176

Please sign in to comment.