Last active
June 26, 2021 19:54
-
-
Save aau8/c63180994817037e04af54f42fa10792 to your computer and use it in GitHub Desktop.
Отправка формы в Telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = $_POST['user_name']; | |
$phone = $_POST['user_phone']; | |
$email = $_POST['user_email']; | |
$token = ""; // http://joxi.ru/v295MB7tzM6g72 - при создании бота в BotFather дается токен | |
$chat_id = ""; /* https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXXX/getUpdates, где, XXXXXXXXXXXXXXXXXXXXXXX - токен вашего бота, полученный ранее. http://joxi.ru/p27DqBgcWqBVXA - где потом взять chat_id. Сначала бота нужно добавить в группу и отправить сообщение. id у бота начинается с минуса*/ | |
$arr = array( | |
'Имя пользователя: ' => $name, | |
'Телефон: ' => $phone, | |
'Email' => $email | |
); | |
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) { | |
header('Location: thank-you.html'); | |
} else { | |
echo "Error"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment