public function contactAction()
 {
     $sujet = $_POST['sujet'];
     $message = $_POST['message'];
     $destinataire = $_POST['idmedecin'];
     $repository = $this->getDoctrine()->getRepository('PortailFrontBundle:User');
     $med = $repository->findOneBy(array('id' => $destinataire));
     $usercurrent = $this->get('security.context')->getToken()->getUser();
     $em = $this->getDoctrine()->getEntityManager();
     $email = new Contact();
     $email->setSujet($sujet);
     $email->setMessage($message);
     $email->setExpediteur($usercurrent);
     $email->setDestinataire($med);
     $email->setDateenvoi(new \DateTime());
     $em->persist($email);
     $em->flush();
     $msg = \Swift_Message::newInstance()->setSubject($sujet)->setFrom(array($usercurrent->getEmail() => 'ContactHorus'))->setTo($med->getEmail())->setBody($message);
     $this->get('mailer')->send($msg);
     return $this->render('PortailAnnuaireBundle:AnnuaireMedecin:validation.html.twig', array('return' => 'Message Envoyé'));
 }
 public function envoiAction(Request $request)
 {
     if ('POST' === $request->getMethod()) {
         $destinataire = $request->request->get('destinataire');
         $sujet = $request->request->get('sujet');
         $msg = $request->request->get('message');
         $repository = $this->getDoctrine()->getRepository('PortailFrontBundle:User');
         $user = $repository->findOneBy(array('username' => $destinataire));
         $usercurrent = $this->get('security.context')->getToken()->getUser();
         $em = $this->getDoctrine()->getEntityManager();
         $email = new Contact();
         $email->setSujet($sujet);
         $email->setMessage($msg);
         $email->setExpediteur($usercurrent);
         $email->setDestinataire($user);
         $email->setDateenvoi(new \DateTime());
         $em->persist($email);
         $em->flush();
         $message = \Swift_Message::newInstance()->setSubject($sujet)->setFrom(array($usercurrent->getEmail() => 'ContactHorus'))->setTo($user->getEmail())->setBody($msg);
         $this->get('mailer')->send($message);
     }
     return $this->render('PortailFrontBundle:Accueil:validation.html.twig', array('return' => 'Message Envoyé'));
 }