asd
$.ajax({
url: '<?php bloginfo('template_url'); ?>/sendtelegram.php',
type: 'POST',
processData: false,
contentType: false,
data: formData
}).done(function(telegramResult) {
console.log('Telegram result:', telegramResult);
}).fail(function() {
console.error('Ошибка при отправке в telegram.php');
});
sendtelegram.php
herl
<?php
require_once(dirname(dirname(dirname(__DIR__))).'/wp-load.php');
// Telegram Bot Token и Chat ID
$botToken = 'Токен_бота';
$chatId = 'ID_чата';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$message = "Новое сообщение с сайта: vortex-pharma.com\n\n";
// Обрабатываем данные из POST-запроса
foreach ($_POST as $key => $value) {
if (is_array($value)) {
$message .= str_replace('_', ' ', $key) . ': ' . implode(', ', $value) . "\n";
} else {
$message .= str_replace('_', ' ', $key) . ': ' . $value . "\n";
}
}
// Отправка сообщения в Telegram
$url = "https://api.telegram.org/bot$botToken/sendMessage";
$data = [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'HTML'
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
}
?>
adsas