Esempio n. 1
0
 /**
  * Validate _POST and send email
  *
  * @throws Error
  */
 public function postContactAction()
 {
     $validation = new Validation();
     $validation->rules(['fullName' => 'required', 'email' => 'required|email', 'repeatEmail' => 'same:email', 'content' => 'required|length:10,5000']);
     $valid = $validation->validate($_POST);
     if (!$valid) {
         $this->view->setVar('errors', $validation->getMessages());
         $this->flash->warning(_t('flash/warning/errors'));
     } else {
         // Prepare an email
         $email = new Email();
         $email->prepare(_t('contact'), $this->config->app->admin, 'email/contact', ['fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')]);
         $email->addReplyTo($this->request->getPost('email'));
         // Try to send email
         if ($email->Send() === true) {
             $this->flash->success(_t('flash/success/contact'));
             unset($_POST);
         } else {
             throw new Error($email->ErrorInfo);
         }
     }
 }