em = $entityManager; $this->mailer = $mailer; } public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, \Swift_Mailer $mailer ) { $em = $this->em->getRepository( Owner::class ); $admin_user = $foundOwner; $poll = $newpoll; // anti spam , limit to every minute $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(); $templateVars = [ 'owner' => $admin_user, 'poll' => $poll, 'title' => 'Création de sondage - ' . $poll->getTitle(), 'email_template' => 'emails/creation-mail.html.twig', ]; $message = ( new Swift_Message( 'Framadate - mes sondages' ) ) ->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->setContentType('text/html') ->setCharset('UTF-8') ->setTo( $admin_user->getEmail() ) ->htmlTemplate($templateVars[ 'email_template' ]) ->context( $templateVars); // send email return $mailer->send( $message ); } /** * send created polls to an owner * @param Owner $foundOwner * * @return int * @throws \Exception */ public function sendOwnerPollsAction( Owner $foundOwner ) { $em = $this->em->getRepository( Owner::class ); $admin_user = $foundOwner; // anti spam , limit to every minute $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' => $admin_user, 'title' => $titleEmail, 'email_template' => 'emails/owner-polls.html.twig', ]; $email = ( new TemplatedEmail( ) ) ->from( 'ne-pas-repondre@framadate-api.cipherbliss.com' ) ->to( new Address($admin_user->getEmail() ) ) ->subject($titleEmail) ->htmlTemplate($templateVars[ 'email_template' ]) ->context( $templateVars); // send email return $this->mailer->send( $email ); } }