You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
<?php
|
|
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
|
|
|
|
use Bitrix\Main\Config\Option;
|
|
|
|
$response = array();
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$name = trim($_POST["name"]);
|
|
$phone = trim($_POST["phone"]);
|
|
$recaptcha_response = trim($_POST["recaptcha_response"]);
|
|
|
|
if ($recaptcha_response){
|
|
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
|
|
$recaptcha_secret_key = '6LcSCXArAAAAAEdhWbATecK4jwMK9WvZbUV2szrY';
|
|
|
|
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret_key . '&response=' . $recaptcha_response);
|
|
$recaptcha = json_decode($recaptcha);
|
|
|
|
//score от 0.1 до 1.0
|
|
if ($recaptcha->score <= 0.4) return;
|
|
}
|
|
|
|
if (empty($name) || empty($phone)) {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Заполните все поля'
|
|
);
|
|
} else {
|
|
$to = Option::get("main", "email_from");
|
|
|
|
|
|
if (empty($to)) {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Ошибка конфигурации почты'
|
|
);
|
|
} else {
|
|
// Отправка почты через почтовое событие Битрикс
|
|
CEvent::Send(
|
|
"CONSULTATION_REQUEST",
|
|
SITE_ID,
|
|
array(
|
|
"NAME" => $name,
|
|
"PHONE" => $phone,
|
|
"EMAIL_TO" => $to
|
|
)
|
|
);
|
|
|
|
$response = array(
|
|
'success' => true,
|
|
'message' => 'Заявка успешно отправлена'
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Неверный метод запроса'
|
|
);
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($response);
|