function actionIndex() { $managers = $this->model->getManagers(); /* Google capcha settings */ $config = parse_ini_file(ROOT . "/app/config/config.ini"); $secret = $config['Secret_key']; $publicKey = $config['Site_key']; if ($_SERVER["REQUEST_METHOD"] == "POST") { $recaptcha = $_POST['g-recaptcha-response']; if (!empty($recaptcha)) { $google_url = "https://www.google.com/recaptcha/api/siteverify"; $ip = $_SERVER['REMOTE_ADDR']; $url = $google_url . "?secret=" . $secret . "&response=" . $recaptcha . "&remoteip=" . $ip; $res = $this->getCurlData($url); $res = json_decode($res, true); //reCaptcha введена if ($res['success']) { $fio = ClearInput::clearInput($_POST['fio'], 's'); if (mb_strlen($fio) < 6) { $errors[] = 'Поле ФИО должно иметь больше 6 символов'; } if (!($phone = ClearInput::cheackPhone($_POST['tel']))) { $errors[] = 'Телефон должен быть из 10 цифр например: 044 537 02 22'; } if (!($email = ClearInput::validate_email($_POST['email']))) { $errors[] = 'Email не валидный'; } $message = ClearInput::clearInput($_POST['message'], 's'); if (mb_strlen($message) < 6) { $errors[] = 'Сообщение должно иметь больше 6 символов'; } } else { $errors[] = "Please re-enter your reCAPTCHA."; } } else { $errors[] = "Please re-enter your reCAPTCHA."; } if (!isset($errors)) { $body = "ФИО: {$fio} <br/>\n Телефон: {$phone} <br/>\n Email: {$email} <br/>\n {$message}"; $subject = 'Форма связаться с нами'; $emails = $config['admin_email']; try { $mail = new SendEmail($body, $emails, $subject); $result = 'Письмо успешно отправлено'; } catch (Exception $e) { $errors[] = $e->getMessage(); } } } $products = new ProductsModel(); $data = array('title' => 'Контакты', 'is_left_slider' => true, 'is_right_slider' => true, 'is_logged' => Session::is_logged(), 'categories' => $products->get_categories(), 'products' => $products->get_data(), 'managers' => $managers, 'errors' => isset($errors) ? $errors : null, 'result' => isset($result) ? $result : null, 'capchaPublicKey' => $publicKey); $this->view->render('contact_view.twig', $data); }