Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
44f8c12c
Commit
44f8c12c
authored
Aug 22, 2018
by
Mat
Browse files
le service newsletter envoie le corps du message dans un template twig
parent
11bd0c2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/PotageBundle/Resources/views/Mail/bodyMail.html.twig
View file @
44f8c12c
<!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
src/PotageBundle/Services/Newsletter.php
View file @
44f8c12c
...
...
@@ -2,31 +2,37 @@
namespace
PotageBundle\Services
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
class
Newsletter
{
private
$
m
ai
l
er
;
private
$
cont
ai
n
er
;
/**
* Newsletter constructor.
*
* @param
\Swift_M
ai
l
er
$m
ai
l
er
* @param
Cont
ai
n
er
Interface $cont
ai
n
er
*/
public
function
__construct
(
\
Swift_M
ai
l
er
$m
ai
l
er
)
public
function
__construct
(
Cont
ai
n
er
Interface
$cont
ai
n
er
)
{
$this
->
m
ai
l
er
=
$
m
ai
l
er
;
$this
->
cont
ai
n
er
=
$
cont
ai
n
er
;
}
/**
* @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();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment