Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
modx snipet telegram send formit
$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,
"Название формы" => $formName,
"ip" => $ip,
/*Цикл по массиву (собираем сообщение) */
foreach($arr as $key => $value) {
$txt .= "<b>".$key."</b>: ".$value."%0A";
#Отправляем сообщение
$ch = curl_init(''.$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);
// $fp=fopen("","r");
#Возвращаем true
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment