public function editAction($mid)
 {
     $success = true;
     $errors = array();
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('TuxCoffeeCornerCoreBundle:Mail');
     $mail = $repo->findOneBy(array('id_mail' => $mid));
     if (!$mail) {
         $mail = new Mail();
     }
     $mail->setIdentifier($_POST['identifier']);
     $mail->setSubject($_POST['subject']);
     $mail->setBody($_POST['body']);
     $mail->setTo($_POST['to']);
     $mail->setCc($_POST['cc']);
     $mail->setFrom($_POST['from']);
     $postErrors = $this->get('validator')->validate($mail);
     if (count($postErrors) > 0) {
         $success = false;
         foreach ($postErrors as $error) {
             $errors[] = $error->getMessage();
         }
     } else {
         $em->persist($mail);
         try {
             $em->flush();
         } catch (\Exception $e) {
             $success = false;
             $errors[] = '<b>Uuuh! Some nasty database exception caught:</b> ' . $e->getMessage() . "\n";
         }
     }
     $message = $this->render("TuxCoffeeCornerCoreBundle:adminPages/snippets:" . ($success ? "successMsg" : "errorMsg") . ".html.php", array('errors' => $errors))->getContent();
     return new Response(json_encode(array('success' => $success, 'message' => $message)), 200, array('content-type' => 'application/json'));
 }
 public function testMail(Mail $mail, Customer $customer)
 {
     $config_repo = $this->em->getRepository('TuxCoffeeCornerCoreBundle:Config');
     $suppress_email = strtolower($config_repo->findOneBy(array('name' => "suppress_email"))->getValue());
     if ($suppress_email == "false" || $suppress_email == "f" || $suppress_email == "0") {
         $recipient = $customer->getEmail();
         $super_recipient = $config_repo->findOneBy(array('name' => "super_recipient"))->getValue();
         if ($super_recipient != "") {
             $this->log->writeLog($this->logname, "Supper recipient enabled: set recipient from '{$recipient}' to '{$super_recipient}'", 2);
             $recipient = $super_recipient;
         }
         $sender = $config_repo->findOneBy(array('name' => "system_maintainer"))->getValue();
         if ($mail->getFrom() != "") {
             $sender = $mail->getFrom();
         }
         $header = "From: " . $sender . "\r\n";
         $header .= "Cc: " . $mail->getCc() . "\r\n";
         $header .= "Subject: " . $mail->getSubject() . "\r\n";
         $this->log->writeLog($this->logname, "Testing mail '" . $mail->getIdentifier() . "' on '{$recipient}' with header '" . str_replace("\r\n", "; ", $header) . "'", 3);
         $sent = mail($recipient, $mail->getSubject(), $mail->getBody(), $header);
         $this->log->writeLog($this->logname, "Mail sent: '{$sent}'", $sent ? 3 : 1);
         return $sent;
     } else {
         $this->lastError = "E-Mail suppressed: suppress email: '{$suppress_email}'";
         $this->log->writeLog($this->logname, $this->lastError, 2);
         return false;
     }
 }