Commit 44f8c12c authored by Mat's avatar Mat
Browse files

le service newsletter envoie le corps du message dans un template twig

parent 11bd0c2f
<!doctype html>
<html lang="en">
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
Coucou
un mail de test
<h1>Mon template twig</h1>
{{ body }}
</body>
</html>
\ No newline at end of file
......@@ -2,31 +2,37 @@
namespace PotageBundle\Services;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Newsletter
{
private $mailer;
private $container;
/**
* Newsletter constructor.
*
* @param \Swift_Mailer $mailer
* @param ContainerInterface $container
*/
public function __construct(\Swift_Mailer $mailer)
public function __construct(ContainerInterface $container)
{
$this->mailer = $mailer;
$this->container = $container;
}
/**
* @param $to
* @param $subject
* @param $body
* @return mixed
* @return int
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function sendMail($to, $subject, $body)
{
$mailer = $this->mailer;
$mailer = $this->container->get('mailer');
$twig = $this->container->get('twig');
$from = ['postmaster@potage.domainepublic.site' => 'Potage'];
$message = (new \Swift_Message())
......@@ -34,11 +40,12 @@ class Newsletter
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setBody($body
//$this->render(
// '@Potage/Mail/bodyMail.html.twig',
// array('name' => 'coucou')
//)
->setBody(
$twig->render('@Potage/Mail/bodyMail.html.twig', array(
'body' => $body,
'name' => 'coucou'
)),
'text/html'
);
//$attachment = \Swift_Attachment::fromPath();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment