-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJangoMailFosUser.php
More file actions
69 lines (58 loc) · 1.8 KB
/
JangoMailFosUser.php
File metadata and controls
69 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Netpeople\JangoMailBundle;
use Netpeople\JangoMailBundle\JangoMail;
use FOS\UserBundle\Mailer\TwigSwiftMailer;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Netpeople\JangoMailBundle\Emails\Email;
use Netpeople\JangoMailBundle\Exception\JangoMailException;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Netpeople\JangoMailBundle\Recipients\Recipient;
/**
* Description of JangoMailFosUser
*
* @author maguirre
*/
class JangoMailFosUser extends TwigSwiftMailer
{
/**
*
* @var JangoMail
*/
protected $jango;
/**
*
* @var LoggerInterface
*/
protected $logger;
function __construct(JangoMail $jango, UrlGeneratorInterface $router, \Twig_Environment $twig, array $parameters, LoggerInterface $logger = null)
{
$this->jango = $jango;
$this->router = $router;
$this->twig = $twig;
$this->parameters = $parameters;
}
/**
* @param string $templateName
* @param array $context
* @param string $fromEmail
* @param string $toEmail
*/
protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
{
$template = $this->twig->loadTemplate($templateName);
$subject = $template->renderBlock('subject', $context);
$textBody = $template->renderBlock('body_text', $context);
$htmlBody = $template->renderBlock('body_html', $context);
$email = new Email();
$email->addRecipient(new Recipient($toEmail))
->setSubject($subject)
->setMessage($htmlBody ? : $textBody);
try {
$this->jango->send($email);
} catch (JangoMailException $e) {
if($this->logger){
$this->logger->error($e->getMessage());
}
}
}
}