em = $entityManager; $transport = new EsmtpTransport(); $mailer = new Mailer($transport); $this->mailer = $mailer; } public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, MailerInterface $mailer ) { $em = $this->em->getRepository( Owner::class ); $admin_user = $foundOwner; $poll = $newpoll; // anti spam , limit to every minute TODO $templateVars = [ 'owner' => $admin_user, 'poll' => $poll, 'title' => 'Création de sondage - ' . $poll->getTitle(), 'email_template' => 'emails/creation-mail.html.twig', ]; $email = ( new Email( ) ) ->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->setContentType( 'text/html' ) ->setCharset( 'UTF-8' ) ->subject('Framadate - mes sondages') ->setTo( $admin_user->getEmail() ) ->htmlTemplate( $templateVars[ 'email_template' ] ) ->context( $templateVars ); // send email return $mailer->send( $email ); } /** * send created polls to an owner * * @param Owner $foundOwner * * @return int * @throws Exception */ public function sendOwnerPollsAction( Owner $foundOwner ) { // anti spam , limit to every minute TODO // $lastSend = $admin_user->getRequestedPollsDate(); // $now = new \DateTime(); // if ( date_diff( $lastSend, $now ) < 60 ) { // // too soon! // die( 'too soon!' ); // } // $admin_user->setRequestedPollsDate( $now ); // $em->persist( $admin_user ); // $em->flush(); $titleEmail = 'Framadate | Mes sondages'; $templateVars = [ 'owner' => $foundOwner, 'title' => $titleEmail, 'email_template' => 'emails/owner-list.html.twig', ]; $email = ( new TemplatedEmail() ) ->from( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->to( new Address( $foundOwner->getEmail() ) ) ->subject( $titleEmail ) ->htmlTemplate( $templateVars[ 'email_template' ] ) ->context( $templateVars ); // send email return $this->mailer->send( $email ); } }