Skip to content

Instantly share code, notes, and snippets.

@abcprintf
Last active March 16, 2019 04:33
Show Gist options
  • Save abcprintf/c5f81e78ff648b920ebb499ce6406cff to your computer and use it in GitHub Desktop.
Save abcprintf/c5f81e78ff648b920ebb499ce6406cff to your computer and use it in GitHub Desktop.
<?php
$apiToken = ""; // Your Token
$chat_id = ""; // Your Chat ID
$text = $_GET['text'];
// V1
/*
$params = [
'chat_id' => $chat_id,
'text' => $text
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($params));
echo $response;
*/
// V2
$url = "https://api.telegram.org/bot$apiToken/sendMessage?";
$postfields = array(
'chat_id' => $chat_id,
'disable_notification' => "False",
'parse_mode' => "HTML",
'text' => "<b>$text</b> \n xxx \n <a href=\"https://url.png\" target=\"_blank\">link</a>",
);
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curld, CURLOPT_URL,$url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close ($curld);
// Handle the response
$result = explode(';',$output);
$result_array = json_decode($result[0]);
//echo "<pre>", print_r(json_decode($result[0])), "</pre>";
if ($result[0] == "Error") {
echo "Error message: $result[0]";
die;
} else {
echo "Message ID: $result[0];";
}
// Simple
// http://localhost/Telegram_Send_Message_PHP.php?text=abcprintf
?>
@abcprintf
Copy link
Author

get chat_id

https://api.telegram.org/bot*** Token ***/getUpdates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment