Esempio n. 1
0
 public function newAction()
 {
     $form = new NewMailForm();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost()) != false) {
             $mail = new Mail();
             $mail->assign(array('fk_user' => $this->session->get('authenticated')['id'], 'state' => 'output', 'subject' => $this->request->getPost('subject'), 'content' => $this->request->getPost('content'), 'date' => date('Y-m-d H:i:s'), 'active' => 1));
             if ($mail->save()) {
                 $num = $mail->id_mail;
                 $str = $this->request->getPost('adress');
                 $adresses = explode(",", $str);
                 for ($i = 0; $i < count($adresses); $i++) {
                     $adresse = new Adressee();
                     if (filter_var($adresses[$i], FILTER_VALIDATE_EMAIL)) {
                         $adresse->assign(array('adresse' => $adresses[$i], 'id_mail' => $num, 'active' => 1));
                         if ($adresse->save()) {
                         }
                     } else {
                         echo "<script>alert('La dirección de correo:  ({$adresses[$i]}) es incorrecta por lo cual no se agregara a los destinatarios del email que desea enviar, solo los correctos.')</script>";
                     }
                 }
                 return $this->response->redirect('dashboard');
             } else {
                 echo "<h5>Upps! Data couldn't be saved :(... Try again...</h5>";
             }
             $this->flash->error($mail->getMessages());
         }
     }
     $this->view->form = $form;
 }