From e235986483204d9814c5ba36ac86aca8a2eb5e3e Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Thu, 16 Apr 2020 17:22:33 +0200 Subject: [PATCH] other --- .env | 2 +- config/packages/dev/swiftmailer.yaml | 2 +- src/Service/MailService.php | 92 +++++++++++++++------------- 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/.env b/.env index 75ddb21..524daeb 100755 --- a/.env +++ b/.env @@ -44,5 +44,5 @@ SUPPORT_EMAIL=admin_framadate@yopmail.com ###< symfony/swiftmailer-bundle ### ###> symfony/mailer ### -# MAILER_DSN=smtp://localhost +MAILER_DSN=smtp://localhost ###< symfony/mailer ### diff --git a/config/packages/dev/swiftmailer.yaml b/config/packages/dev/swiftmailer.yaml index 8cb6afe..007a640 100755 --- a/config/packages/dev/swiftmailer.yaml +++ b/config/packages/dev/swiftmailer.yaml @@ -1,4 +1,4 @@ # See https://symfony.com/doc/current/email/dev_environment.html swiftmailer: # send all emails to a specific address - delivery_addresses: ['contact@cipherbliss.com'] +# delivery_addresses: ['contact@cipherbliss.com'] diff --git a/src/Service/MailService.php b/src/Service/MailService.php index c6f6c79..4507faa 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -9,12 +9,10 @@ use App\Entity\Owner; use App\Entity\Poll; use Doctrine\ORM\EntityManagerInterface; use Exception; -use http\Header; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; use Symfony\Component\Mime\Address; -use Symfony\Component\Mime\Email; class MailService { @@ -26,10 +24,12 @@ class MailService { private $mailer; +// public function __construct( EntityManagerInterface $entityManager , Mailer $mailer) { public function __construct( EntityManagerInterface $entityManager ) { $this->em = $entityManager; $transport = new EsmtpTransport(); $this->mailer = new Mailer( $transport ); +// $this->mailer = $mailer; } /** @@ -38,7 +38,7 @@ class MailService { * * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface */ - public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null) { + public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null ) { // anti spam , limit to every minute TODO @@ -46,7 +46,7 @@ class MailService { 'owner' => $foundOwner, 'from' => 'ne-pas-repondre@framadate-api.cipherbliss.com', 'poll' => $poll, - 'title' => 'Création de sondage - ' . ($poll? $poll->getTitle() : $poll), + 'title' => 'Création de sondage - ' . ( $poll ? $poll->getTitle() : $poll ), 'email_template' => 'emails/creation-mail.html.twig', ]; @@ -92,6 +92,7 @@ class MailService { 'email_template' => 'emails/owner-list.html.twig', ]; $this->sendMailWithVars( $config ); + return 1; } @@ -99,9 +100,9 @@ class MailService { public function sendCommentNotification( Comment $comment ) { $config = [ - 'comment' => $comment, + 'comment' => $comment, 'owner' => $comment->getOwner(), - 'title' => 'Framadate | commentaire de '.$comment->getOwner()->getPseudo(). ' _ sondage '. $comment->getPoll()->getTitle(), + 'title' => 'Framadate | commentaire de ' . $comment->getOwner()->getPseudo() . ' _ sondage ' . $comment->getPoll()->getTitle(), 'email_template' => 'emails/comment-notification.html.twig', ]; @@ -117,49 +118,58 @@ class MailService { */ public function sendMailWithVars( $config ) { - if(!$config['poll']){ - $config['poll'] = new Poll(); + if ( ! $config[ 'poll' ] ) { + $config[ 'poll' ] = new Poll(); } $emailChoicesTemplates = [ - 'creation_poll' => 'creation-mail.html.twig', - 'edit_poll' => 'modification-notification-mail.html.twig', - 'creation_poll_admin' => 'author-mail.html.twig', - 'owner_list' => 'owner-list.html.twig', - 'expiration' => 'expiration-mail.html.twig', - 'creation_comment' => 'comment-notification.html.twig', - 'creation_vote' => 'vote-notification.html.twig', + 'creation_poll' => 'creation-mail.html.twig', + 'edit_poll' => 'modification-notification-mail.html.twig', + 'creation_poll_admin' => 'author-mail.html.twig', + 'owner_list' => 'owner-list.html.twig', + 'expiration' => 'expiration-mail.html.twig', + 'creation_comment' => 'comment-notification.html.twig', + 'creation_vote' => 'vote-notification.html.twig', ]; $emailChoicesTitles = [ - 'creation_poll' => 'Framadate | Création de sondage - lien public - ' . $config['poll']->getTitle(), - 'edit_poll' => 'Framadate | Modification de sondage - ' . $config['poll']->getTitle(), - 'creation_poll_admin' => 'Framadate | Création de sondage - lien admin - ', - 'owner_list' => 'Framadate | Vos sondages créés', - 'expiration' => 'Framadate | Notice d\'expiration du sondage '. $config['poll']->getTitle(), - 'creation_comment' => 'Framadate | Commentaire de "' . $config['owner']->getPseudo() . '" - sondage ' . $config['poll']->getTitle(), - 'creation_vote' => 'Framadate | Vote de "' . $config['owner']->getPseudo() . '" - sondage ' . $config['poll']->getTitle(), + 'creation_poll' => 'Framadate | Création de sondage - lien public - ' . $config[ 'poll' ]->getTitle(), + 'edit_poll' => 'Framadate | Modification de sondage - ' . $config[ 'poll' ]->getTitle(), + 'creation_poll_admin' => 'Framadate | Création de sondage - lien admin - ', + 'owner_list' => 'Framadate | Vos sondages créés', + 'expiration' => 'Framadate | Notice d\'expiration du sondage ' . $config[ 'poll' ]->getTitle(), + 'creation_comment' => 'Framadate | Commentaire de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(), + 'creation_vote' => 'Framadate | Vote de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(), ]; -// $email = ( new Email() ) -// ->from( new Address( $config[ 'from' ] ) ) + $email = ( new TemplatedEmail() ) + ->from( new Address( $config[ 'from' ] ) ) +// ->setHeaders( [new Header('charset', 'UTF-8' )]) + ->subject( $config[ 'title' ] ) + ->to( $config[ 'owner' ]->getEmail() ) + ->htmlTemplate( $config[ 'email_template' ] ) + ->context( $config ); + + +// $email = ( new \Swift_Mime_SimpleMessage($config[ 'from' ]) ) +// ->setFrom( new Address( $config[ 'from' ] ) ) //// ->setHeaders( [new Header('charset', 'UTF-8' )]) -// ->subject( $config[ 'title' ] ) -// ->to( $config[ 'owner' ]->getEmail() ) -// ->htmlTemplate( $config[ 'email_template' ] ) -// ->context( $config ); - $email = (new TemplatedEmail()) - ->from('fabien@example.com') - ->to(new Address('ryan@example.com')) - ->subject('Thanks for signing up!') +// ->setSubject( $config[ 'title' ] ) +// ->setTo( $config[ 'owner' ]->getEmail() ) +// ->setBody("ble blah bleuh strong text swift mailer","text/html"); - // path of the Twig template to render - ->htmlTemplate('emails/footer.html.twig') - - // pass variables (name => value) to the template - ->context([ - 'expiration_date' => new \DateTime('+7 days'), - 'username' => 'foo', - ]) - ; +// $email = (new TemplatedEmail()) +// ->from('fabien@example.com') +// ->to(new Address('ryan@example.com')) +// ->subject('Thanks for signing up!') +// +// // path of the Twig template to render +// ->htmlTemplate('emails/footer.html.twig') +// +// // pass variables (name => value) to the template +// ->context([ +// 'expiration_date' => new \DateTime('+7 days'), +// 'username' => 'foo', +// ]) +// ; // send email return $this->