Skip to content

Instantly share code, notes, and snippets.

@rizkyramadhan21
Last active May 22, 2021 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizkyramadhan21/5ac9d0848be91a403c6416d1326a69ca to your computer and use it in GitHub Desktop.
Save rizkyramadhan21/5ac9d0848be91a403c6416d1326a69ca to your computer and use it in GitHub Desktop.
Simple php script for sending telegram bot message
<?php
/* -----------------------------------------------------
Simple PHP script for Sending Telegram Bot Message
~ Iky | https://www.wadagizig.com
------------------------------------------------------ */
function sendMessage($telegram_id, $message_text, $secret_token) {
$url = "https://api.telegram.org/bot" . $secret_token . "/sendMessage?parse_mode=markdown&chat_id=" . $telegram_id;
$url = $url . "&text=" . urlencode($message_text);
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
curl_close($ch);
}
/*----------------------
only basic POST method :
-----------------------*/
$telegram_id = $_POST ['telegram_id'];
$message_text = $_POST ['message_text'];
/*--------------------------------
Isi TOKEN dibawah ini:
--------------------------------*/
$secret_token = "Isi TOKEN disini";
sendMessage($telegram_id, $message_text, $secret_token);
echo "<script>alert('Pesan berhasil terkirim!'); window.location.href = './';</script>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment