ihtiyacı olan arkadaşlar için örnek bu şekildedir
-- -- Tablo için tablo yapısı `telegram_bildirim` --
CREATE TABLE `telegram_bildirim` ( `id` int(11) NOT NULL, `bot_token` text NOT NULL, `chat_id` text NOT NULL, `aktif` tinyint(1) DEFAULT 1 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- -- Tablo döküm verisi `telegram_bildirim` --
INSERT INTO `telegram_bildirim` (`id`, `bot_token`, `chat_id`, `aktif`) VALUES (1, '67015xxx75:AAxxxxxQ57CRxxxxxxx_s2z3Mk', '-100xxxxxx88', 1);
//TG
function sendTelegramNotification($conn, $data)
{
// sql adp
$stmt = $conn->prepare("SELECT bot_token, chat_id FROM telegram_bildirim WHERE aktif = 1 LIMIT 1");
$stmt->execute();
$result2 = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result2 || empty($result2['bot_token']) || empty($result2['chat_id'])) {
error_log("Telegram bilgileri eksik veya bulunamadı.");
return;
}
$botToken = $result2['bot_token'];
$chatId = $result2['chat_id'];
$message = "✨ *YENİ REZERVASYON BİLDİRİMİ* ✨\n"
. str_repeat('―', 28) . "\n\n"
. "👤 *MİSAFİR BİLGİLERİ*\n"
. "▸ Ad Soyad: `{$data['name']} {$data['surname']}`\n"
. "▸ Telefon: `{$data['phone']}`\n"
. "▸ Doğum Tarihi: `{$data['birthdate']}`\n\n"
. "🏡 *KONAKLAMA DETAYLARI*\n"
. "▸ Villa: `{$data['selected_bungalow']}`\n"
. "▸ Giriş: `{$data['checkin_date']}`\n"
. "▸ Çıkış: `{$data['checkout_date']}`\n"
. "▸ Misafir Sayısı: `👨*👩*👧*👦 Yetişkin: {$data['*****_count']} | Çocuk: {$data['child_count']}`\n\n"
. "💰 *ÖDEME BİLGİSİ*\n"
. "▸ Toplam Ücret: `{$data['price']} ₺`\n\n"
. "📌 *EK NOT*\n"
. "```" . (!empty($data['extra_requests']) ? $data['extra_requests'] : 'Belirtilmedi') . "```\n\n"
. str_repeat('・', 14) . "\n"
. "⏳ Bildirim Zamanı: _" . date("d.m.Y H:i") . "_";
$payload = [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'Markdown'
];
$url = 'https://api.telegram.org/bot' . $botToken . '/sendMessage';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
sendTelegramNotification($conn, $data);