From 79c4bd251959cdb9aa780085021a83283284e9ae Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Thu, 16 Apr 2020 17:40:00 +0200 Subject: [PATCH] testing stuff --- src/Service/MailService.php | 53 ++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/Service/MailService.php b/src/Service/MailService.php index 4507faa..fef8ae0 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -9,10 +9,9 @@ use App\Entity\Owner; use App\Entity\Poll; use Doctrine\ORM\EntityManagerInterface; use Exception; -use Symfony\Bridge\Twig\Mime\TemplatedEmail; -use Symfony\Component\Mailer\Mailer; -use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; -use Symfony\Component\Mime\Address; +use Swift_Mailer; +use Swift_Message; +use Swift_SmtpTransport; class MailService { @@ -26,10 +25,15 @@ class MailService { // 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; + $this->em = $entityManager; + + // Create the Transport + $transport = new Swift_SmtpTransport( 'localhost', 25 ); + +// Create the Mailer using your created Transport + $mailer = new Swift_Mailer( $transport ); + + $this->mailer = $mailer; } /** @@ -83,6 +87,7 @@ class MailService { * * @return int|void * @throws Exception + * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface */ public function sendOwnerPollsAction( Owner $owner ) { @@ -97,6 +102,11 @@ class MailService { } + /** + * @param Comment $comment + * + * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface + */ public function sendCommentNotification( Comment $comment ) { $config = [ @@ -106,7 +116,7 @@ class MailService { 'email_template' => 'emails/comment-notification.html.twig', ]; - return $this->sendMailWithVars( $config ); + $this->sendMailWithVars( $config ); } /** @@ -139,14 +149,21 @@ class MailService { 'creation_comment' => 'Framadate | Commentaire de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(), 'creation_vote' => 'Framadate | Vote de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(), ]; + // Create a message + $message = ( new Swift_Message( 'Wonderful Subject' ) ) + ->setFrom( [ 'contact@framadate-api.cipherbliss.com' ] ) + ->setTo( ['contact@cipherbliss.com'] ) + ->setBody( 'Here is the message itself' ); - $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 ); +// Send the message + $numSent = $this->mailer->send( $message ); + printf( "Sent %d messages\n", $numSent ); +// $email = ( new TemplatedEmail() ) +// ->from( new Address( $config[ 'from' ] ) ) +// ->subject( $config[ 'title' ] ) +// ->to( $config[ 'owner' ]->getEmail() ) +// ->htmlTemplate( $config[ 'email_template' ] ) +// ->context( $config ); // $email = ( new \Swift_Mime_SimpleMessage($config[ 'from' ]) ) @@ -172,7 +189,7 @@ class MailService { // ; // send email - return $this-> - mailer->send( $email ); + + } }