Skip to content

Instantly share code, notes, and snippets.

@oleglr
Forked from palnov/sendform-to-telegram.php
Created January 25, 2022 12:41
Show Gist options
  • Save oleglr/3a55ab76ccda8cf94b527747e3bc9d0f to your computer and use it in GitHub Desktop.
Save oleglr/3a55ab76ccda8cf94b527747e3bc9d0f to your computer and use it in GitHub Desktop.
Отправка данных с форм в телеграм
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST['name']) && !empty($_POST['phone'])){
if (isset($_POST['name'])) {
if (!empty($_POST['name'])){
$uname = strip_tags($_POST['name']);
$unameFieldset = "Имя:%20";
}
}
if (isset($_POST['phone'])) {
if (!empty($_POST['phone'])){
$uphone = strip_tags($_POST['phone']);
$uphoneFieldset = "Телефон:%20";
}
}
if (isset($_POST['formservices'])) {
if (!empty($_POST['formservices'])){
$formInfo = strip_tags($_POST['formservices']);
$formInfoFieldset = "Форма:%20";
}
}
$token = "362962058:AAGmyIE8bpTKOPgiSGZ_wb3U8H-V8HQS7yA";
$chat_id = "-235156782";
$arr = array(
$unameFieldset => $uname,
$uphoneFieldset => $uphone,
$formInfoFieldset => $formInfo
);
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 == 'false') {
echo '<p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p>';
} else {
echo '<h3 class="success">Спасибо! В ближайшее время наш менеджер свяжется с Вами.</h3>';
}
} else {
echo '<p class="fail">Ошибка. Вы заполнили не все обязательные поля!</p>';
}
} else {
header ("Location: http://vk.com"); // главная страница вашего лендинга
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment