Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
11bd0c2f
Commit
11bd0c2f
authored
Aug 22, 2018
by
Mat
Browse files
Envoi réussi d'un second mail : passe par un service
parent
6bc3f282
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/config/services.yml
View file @
11bd0c2f
...
...
@@ -33,3 +33,7 @@ services:
# PotageBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
PotageBundle\Services\Newsletter
:
#arguments: ["email", "string", "text"]
src/PotageBundle/Command/SendMailCommand.php
View file @
11bd0c2f
...
...
@@ -2,7 +2,7 @@
namespace
PotageBundle\Command
;
use
PotageBundle\Services\Newsletter
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Output\OutputInterface
;
...
...
@@ -19,39 +19,36 @@ class SendMailCommand extends ContainerAwareCommand
->
setDescription
(
"Envoie un biess mail !"
);
}
public
$
mail
er
;
public
$
newslett
er
;
/**
* SendMailCommand constructor.
*
* @param
\Swift_Mailer $mail
er
* @param
Newsletter $newslett
er
*/
public
function
__construct
(
\
Swift_Mailer
$mail
er
)
public
function
__construct
(
Newsletter
$newslett
er
)
{
parent
::
__construct
();
$this
->
mailer
=
$mail
er
;
$this
->
newsletter
=
$newslett
er
;
}
/**
* Vérifie que les offres en cours n'ont pas expiré.
* Si c'est le cas, le statut est changé et un mail est envoyé aux maraichers.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
$message
=
(
new
\
Swift_Message
(
'Hello Email'
))
->
setFrom
(
'postmaster@potage.domainepublic.site'
)
->
setTo
(
'mat@collectifs.net'
)
->
setBody
(
'coucou, ceci est un test'
,
'text/html
'
)
;
$this
->
mailer
->
send
(
$message
);
$output
->
writeln
(
'
un mail envoyé'
);
$ret
=
$this
->
newsletter
->
sendMail
(
'mat@collectifs.net'
,
'[Potage] envoi depuis la commande'
,
'body du mail de test
'
)
;
$retMsg
=
(
$ret
===
1
)
?
"
\e
[1;32mDone
\e
[0m
\n
"
:
"
\e
[1;31mError
\e
[0m
\n
"
;
$output
->
writeln
(
'
Sending mail .. '
.
$retMsg
);
}
}
src/PotageBundle/Controller/DefaultController.php
View file @
11bd0c2f
...
...
@@ -2,7 +2,7 @@
namespace
PotageBundle\Controller
;
use
PotageBundle\Services\Newsletter
;
class
DefaultController
extends
MasterController
{
...
...
@@ -16,11 +16,21 @@ class DefaultController extends MasterController
}
/**
* @param Newsletter $newsletter
* @return \Symfony\Component\HttpFoundation\Response
*/
public
function
testAction
()
public
function
testAction
(
Newsletter
$newsletter
)
{
return
$this
->
render
(
'@Potage/Default/test.html.twig'
);
$ret
=
$newsletter
->
sendMail
(
'mat@collectifs.net'
,
'[Potage] envoyé depuis la page de test'
,
'body du mail de test'
);
return
$this
->
render
(
'@Potage/Default/test.html.twig'
,
array
(
'retour'
=>
$ret
));
}
/**
...
...
src/PotageBundle/Resources/views/Default/test.html.twig
View file @
11bd0c2f
...
...
@@ -6,7 +6,7 @@
{%
block
content
%}
<h1>
{{
block
(
'title'
)
}}
</h1>
{{
retour
}}
{%
endblock
%}
{%
block
customJS
%}
...
...
src/PotageBundle/Resources/views/Mail/bodyMail.html.twig
0 → 100644
View file @
11bd0c2f
<!doctype html>
<html
lang=
"en"
>
<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
</body>
</html>
\ No newline at end of file
src/PotageBundle/Services/Newsletter.php
0 → 100644
View file @
11bd0c2f
<?php
namespace
PotageBundle\Services
;
class
Newsletter
{
private
$mailer
;
/**
* Newsletter constructor.
*
* @param \Swift_Mailer $mailer
*/
public
function
__construct
(
\
Swift_Mailer
$mailer
)
{
$this
->
mailer
=
$mailer
;
}
/**
* @param $to
* @param $subject
* @param $body
* @return mixed
*/
public
function
sendMail
(
$to
,
$subject
,
$body
)
{
$mailer
=
$this
->
mailer
;
$from
=
[
'postmaster@potage.domainepublic.site'
=>
'Potage'
];
$message
=
(
new
\
Swift_Message
())
->
setFrom
(
$from
)
->
setTo
(
$to
)
->
setSubject
(
$subject
)
->
setBody
(
$body
//$this->render(
// '@Potage/Mail/bodyMail.html.twig',
// array('name' => 'coucou')
//)
);
//$attachment = \Swift_Attachment::fromPath();
return
$mailer
->
send
(
$message
);
}
}
\ No newline at end of file
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