Skip to content

Instantly share code, notes, and snippets.

@asimzeeshan
Forked from AkostDev/send2Telegram
Last active September 24, 2022 02:14
Show Gist options
  • Save asimzeeshan/cfb179ed11a0ecb3e1d7ad45c6076ea3 to your computer and use it in GitHub Desktop.
Save asimzeeshan/cfb179ed11a0ecb3e1d7ad45c6076ea3 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
));
$content = curl_exec($ch);
curl_close($ch);
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment