-
-
Save oleglr/3a55ab76ccda8cf94b527747e3bc9d0f to your computer and use it in GitHub Desktop.
Отправка данных с форм в телеграм
This file contains hidden or 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 | |
| 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