Advertisement
arijulianto

Send Message Telegram Bot

Feb 14th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. function sendMessage($to, $message){
  2.     $url = "https://api.telegram.org/bot" . $bot_token . "/sendMessage";
  3.     $postData = [
  4.         'chat_id' => $to,
  5.         // 'parse_mode' => 'HTML',
  6.         'text' => $message
  7.     ];
  8.     $header = [
  9.         "X-Requested-With: XMLHttpRequest",
  10.         "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
  11.     ];
  12.     $ch = curl_init();
  13.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14.     curl_setopt($ch, CURLOPT_URL, $url);
  15.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  16.     curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);  
  17.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  18.     $response = curl_exec($ch);
  19.     $err = curl_error($ch);
  20.     curl_close($ch);
  21.     if($err){
  22.         $response = $err;
  23.     }
  24.     return json_decode($response, true);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement