function __construct() { $html = MG::get('pages')->getPageByUrl('feedback'); $html['html_content'] = MG::inlineEditor(PREFIX . 'page', "html_content", $html['id'], $html['html_content']); $data = array('dislpayForm' => true, 'meta_title' => $html['meta_title'] ? $html['meta_title'] : $html['title'], 'meta_keywords' => $html['meta_keywords'], 'meta_desc' => $html['meta_desc'], 'html_content' => $html['html_content'], 'title' => $html['title']); // Если пришли данные с формы. if (isset($_POST['send'])) { // Создает модель отправки сообщения. $feedBack = new Models_Feedback(); // Проверяет на корректность вода. $error = $feedBack->isValidData($_POST); $data['error'] = $error; // Если есть ошибки заносит их в переменную. if (!$error) { $_POST['message'] = nl2br($_POST['message']); //Отправляем админам. $sitename = MG::getSetting('sitename'); //$message = str_replace('№', '#', $feedBack->getMessage()); $body = MG::layoutManager('email_feedback', array('msg' => $_POST['message'], 'email' => $feedBack->getEmail(), 'name' => $feedBack->getFio())); $mails = explode(',', MG::getSetting('adminEmail')); foreach ($mails as $mail) { if (preg_match('/^[-._a-zA-Z0-9]+@(?:[a-zA-Z0-9][-a-zA-Z0-9]+\\.)+[a-zA-Z]{2,6}$/', $mail)) { Mailer::addHeaders(array("Reply-to" => $feedBack->getEmail())); Mailer::sendMimeMail(array('nameFrom' => $feedBack->getFio(), 'emailFrom' => $feedBack->getEmail(), 'nameTo' => $sitename, 'emailTo' => $mail, 'subject' => 'Сообщение с формы обратной связи', 'body' => $body, 'html' => true)); } } MG::redirect('/feedback?thanks=1'); } } // Формирует сообщение. if (isset($_REQUEST['thanks'])) { $data = array('message' => 'Ваше сообщение отправлено!', 'dislpayForm' => false, 'meta_title' => 'Обратная связь', 'meta_keywords' => $model->currentCategory['meta_keywords'] ? $model->currentCategory['meta_keywords'] : "Обратная сввязь, быстрое сообщение, вопрос в поддержку", 'meta_desc' => $model->currentCategory['meta_desc'] ? $model->currentCategory['meta_desc'] : "Задайте свой вопрос по средствам формы обратной связи."); } $this->data = $data; }
public function send() { if (empty($_POST['fio']) || empty($_POST['email']) || empty($_POST['message']) || empty($_POST['capcha'])) { $this->messageError = 'Необходимо заполнить все поля!'; return FALSE; } else { if (!preg_match('/^[A-Za-z0-9._-]+@[A-Za-z0-9_-]+.([A-Za-z0-9_-][A-Za-z0-9_]+)$/', $_POST['email'])) { $this->messageError = 'Неверно заполнено поле e-mail!'; return FALSE; } if ($_POST['capcha'] != $_SESSION['capcha']) { $this->messageError = 'Неверно введен код с картинки'; return FALSE; } } $feedBack = new Models_Feedback(); $error = $feedBack->isValidData($_POST); $sitename = MG::getSetting('sitename'); $message = str_replace('№', '#', $feedBack->getMessage()); $mails = explode(',', MG::getSetting('adminEmail')); foreach ($mails as $mail) { if (preg_match('/^[-._a-z0-9]+@(?:[a-z0-9][-a-z0-9]+\\.)+[a-z]{2,6}$/', $mail)) { Mailer::addHeaders(array("Reply-to" => $feedBack->getEmail())); Mailer::sendMimeMail(array('nameFrom' => $feedBack->getFio(), 'emailFrom' => $feedBack->getEmail(), 'nameTo' => $sitename, 'emailTo' => $mail, 'subject' => 'Сообщение с формы обратной связи', 'body' => $message, 'html' => true)); } } $this->messageSucces = 'Ваше сообщение успешно отправлено! В ближайшее время мы свяжемся с вами.'; return TRUE; }