Exemplo n.º 1
0
 public function send(Newsletter $newsletter)
 {
     if ($newsletter->getSent()) {
         return;
     }
     $subscriber = $this->em->getRepository('EnhavoNewsletterBundle:Subscriber')->findBy(array('active' => true));
     for ($i = 0; $i < count($subscriber); $i++) {
         $message = \Swift_Message::newInstance()->setSubject($newsletter->getSubject())->setContentType("text/html")->setFrom($this->config['send_from'])->setTo($subscriber[$i]->getEmail())->setBody($newsletter->getText());
         $this->get('mailer')->send($message);
     }
     $newsletter->setSent(true);
     $this->em->persist($newsletter);
     $this->em->flush();
 }
Exemplo n.º 2
0
 public function sendEmailAction(Request $request)
 {
     $id = $request->get('id');
     $newsletterData = $request->get('enhavo_newsletter_newsletter');
     $currentNewsletter = $this->getDoctrine()->getRepository('EnhavoNewsletterBundle:Newsletter')->find($id);
     if (!$currentNewsletter) {
         $currentNewsletter = new Newsletter();
     }
     $currentNewsletter->setTitle($newsletterData['title']);
     $currentNewsletter->setSubject($newsletterData['subject']);
     $currentNewsletter->setText($newsletterData['text']);
     $currentNewsletter->setSent(true);
     $em = $this->getDoctrine()->getManager();
     $em->persist($currentNewsletter);
     $em->flush();
     $newsletterManager = $this->getNewsletterManager();
     $newsletterManager->send($currentNewsletter);
     return new JsonResponse();
 }