Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
modx snipet telegram send formit
<?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