Skip to content

Instantly share code, notes, and snippets.

@AkostDev
Last active October 7, 2022 13:45
Show Gist options
  • Save AkostDev/7adb191aba00e238dcaa601657bc44c3 to your computer and use it in GitHub Desktop.
Save AkostDev/7adb191aba00e238dcaa601657bc44c3 to your computer and use it in GitHub Desktop.
PHP function for sending message to Telegram (using CURL)
function send2Telegram($id, $msg, $token = '', $silent = false) {
$data = array(
'chat_id' => $id,
'text' => $msg,
'parse_mode' => 'html',
'disable_web_page_preview' => true,
'disable_notification' => $silent
);
if($token != '') {
$ch = curl_init('https://api.telegram.org/bot'.$token.'/sendMessage');
curl_setopt_array($ch, array(
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data
));
curl_exec($ch);
curl_close($ch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment