Last active
October 7, 2022 13:45
-
-
Save AkostDev/7adb191aba00e238dcaa601657bc44c3 to your computer and use it in GitHub Desktop.
PHP function for sending message to Telegram (using CURL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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