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

Commit 5b9b176

Browse files
committed
Add a callback parameter
Allow to modify the mail before it is sent.
1 parent 7ec263b commit 5b9b176

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/MailSender.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig)
2323
/**
2424
* @param string $name
2525
* @param array $context
26+
* @param callable|null $callback a callback to modify the mail before it is sent.
2627
*/
27-
public function send($name, array $context = [])
28+
public function send($name, array $context = [], callable $callback = null)
2829
{
2930
$template = $this->twig->loadTemplate($name);
3031

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

60+
if ($callback) {
61+
$callback($mail);
62+
}
63+
5964
$this->mailer->send($mail);
6065
}
6166

0 commit comments

Comments
 (0)