Last active
September 28, 2023 13:47
-
-
Save PechenkiUA/f5b5d6acdb2c0a15109bfc729198f18d to your computer and use it in GitHub Desktop.
modx snipet telegram send formit
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 | |
$token = "xxxxxxxxxxxxxxxxxxxx"; | |
$chat_id = "0000000"; | |
$values = $hook->getValues(); | |
#Получаем название формы | |
$formName = $modx->getOption('formName', $formit->config, 'form-'.$modx->resource->get('id')); | |
#Получаем ip адрес отправителя | |
$ip = $modx->getOption('REMOTE_ADDR', $_SERVER, ''); | |
#Данные с формы | |
$name = $values['name']; | |
$phone = $values['email']; | |
$message = $values['message']; | |
$site = $value['site']; | |
if($formName == 'form-118'){ | |
$formName = 'Модуль'; | |
} | |
#Создаем массив | |
$arr = array( | |
"Имя" => $name, | |
"Email" => $phone, | |
"Коментарий"=>$message, | |
"Название формы" => $formName, | |
"ip" => $ip, | |
'site'=>$_POST['site']); | |
/*Цикл по массиву (собираем сообщение) */ | |
foreach($arr as $key => $value) { | |
$txt .= "<b>".$key."</b>: ".$value."%0A"; | |
} | |
#Отправляем сообщение | |
$ch = curl_init('https://api.telegram.org/bot'.$token.'/sendMessage?chat_id='.$chat_id.'&parse_mode=html&text='.$txt); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
$html = curl_exec($ch); | |
curl_close($ch); | |
// $fp=fopen("https://bot.pechenki.top/bot.php?Ptoken=ad954fe6ed034ee649ea46fe8f05189b&text=gfgfffg","r"); | |
#Возвращаем true | |
return true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment