Files
triumf-landing/send.php
2024-07-11 17:16:13 +03:00

36 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$token = "";
$chat_id = "";
//Определяем переменные для передачи данных из нашей формы
if ($_POST['act'] == 'order') {
$name = ($_POST['name']);
$phone = ($_POST['phone']);
//Собираем в массив то, что будет передаваться боту
$arr = array(
'Имя:' => $name,
'Телефон:' => $phone
);
//Настраиваем внешний вид сообщения в телеграме
foreach($arr as $key => $value) {
$txt .= "<b>".$key."</b> ".$value."%0A";
};
//Передаем данные боту
$sendToTelegram = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
//Выводим сообщение об успешной отправке
if ($sendToTelegram) {
alert('Спасибо! Ваша заявка принята. Мы свяжемся с вами в ближайшее время.');
}
//А здесь сообщение об ошибке при отправке
else {
alert('Что-то пошло не так. ПОпробуйте отправить форму ещё раз.');
}
}
?>