Skip to content

Instantly share code, notes, and snippets.

@Humayung
Created May 28, 2020 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Humayung/0478df74aa4bbd71d43635f1761b8cf8 to your computer and use it in GitHub Desktop.
Save Humayung/0478df74aa4bbd71d43635f1761b8cf8 to your computer and use it in GitHub Desktop.
Send message telegram bot
<form method=post>
<input type=text name='input_message'>
<input type=submit value='send'>
</form>
<?php
if($_POST){
function sendMessage($message){
if($message != ''){
$url = 'https://api.telegram.org/botXXX:ZZZ/sendMessage';
$data = array('chat_id' => 'zzzzzzzzzz', 'text' => $message);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
}
}
$message = $_POST['input_message'];
sendMessage($message);
// var_dump($result);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment