Last active
November 12, 2024 03:18
-
-
Save WebSofter/2cf771ac0f9bedda535e1265b134ba6c to your computer and use it in GitHub Desktop.
Telegram:PHP:Отправка сообщения пользователю через бота Telegram #php #telegram #mail
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 | |
function setndToTelegram($titleMsg, $senderName, $senderPhone, $yourToken, $yourChatId) | |
{ | |
$token = $yourToken;//"vapiummoscow";//"<ВАШ ТОКЕН>"; | |
$chat_id = $yourChatId;//"ls25081990";//"<ВАШ ID чата>"; | |
//$values = $hook->getValues(); | |
#Получаем название формы | |
//$formName = $modx->getOption('formName', $formit->config, 'form-'.$modx->resource->get('id')); | |
#Получаем ip адрес отправителя | |
//$ip = $modx->getOption('REMOTE_ADDR', $_SERVER, ''); | |
#Данные с формы | |
$name = $senderName;//$values['name-zv']; | |
$phone = $senderPhone;//$values['phone-zv']; | |
#Создаем массив | |
$arr = array( | |
"Имя" => $name, | |
"Телефон" => $phone); | |
//, | |
//"Название формы" => $formName, | |
//"Айпи" => $ip); | |
$txt = "<i>".$titleMsg."</i>%0A"; | |
/*Цикл по массиву (собираем сообщение) */ | |
foreach($arr as $key => $value) { | |
$txt .= "<b>".$key."</b>: ".$value."%0A"; | |
} | |
//$txt = urlencode($txt); | |
#Отправляем сообщение | |
$fp=fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r"); | |
#Возвращаем true | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment