Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
potage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mathieu
potage
Commits
11bd0c2f
Commit
11bd0c2f
authored
Aug 22, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Envoi réussi d'un second mail : passe par un service
parent
6bc3f282
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
22 deletions
+95
-22
app/config/services.yml
app/config/services.yml
+4
-0
src/PotageBundle/Command/SendMailCommand.php
src/PotageBundle/Command/SendMailCommand.php
+15
-18
src/PotageBundle/Controller/DefaultController.php
src/PotageBundle/Controller/DefaultController.php
+13
-3
src/PotageBundle/Resources/views/Default/test.html.twig
src/PotageBundle/Resources/views/Default/test.html.twig
+1
-1
src/PotageBundle/Resources/views/Mail/bodyMail.html.twig
src/PotageBundle/Resources/views/Mail/bodyMail.html.twig
+14
-0
src/PotageBundle/Services/Newsletter.php
src/PotageBundle/Services/Newsletter.php
+48
-0
No files found.
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