Answer the question
In order to leave comments, you need to log in
Why messages are not sent to telegram via php?
I made a small script for sending messages to a telegram group chat.
Because RKN blocks telegrams with us, I use PROXY_HTTP. The open server is locally deployed on the laptop and everything works well. Messages come and everything is fine.
Well, I think it's time to go to the Internet all this. I registered with AWS (Amazon Web Service), created a server, uploaded my php file there and it seems to work, that is, the page does not show any errors. But still nothing comes to telegram. Help please, where to look, where to see what logs? I can't understand anything. I've been tinkering all day.
Code Listing:
<?php
define('TELEGRAM_TOKEN', 'XXXXXX:XXXXXXXXXXXXXXXXX');
define('TELEGRAM_CHATID', '-12343211234321');
#$message = 'Здорова';
$message = $_GET['message'];
message_to_telegram($message);
function message_to_telegram($mess) {
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_URL => 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendMessage',
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 10,
CURLOPT_POSTFIELDS => array(
'chat_id' => TELEGRAM_CHATID,
'text' => $mess,
),
CURLOPT_PROXY => 'qwe-qwe.ra:12354',
CURLOPT_PROXYUSERPWD => 'qwe-qwerty:asdasd',
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
)
);
curl_exec($ch);
}
Answer the question
In order to leave comments, you need to log in
Because server over the hill, then, accordingly, no Proxy is needed there and, accordingly, the code fits in 3 lines. I have it like this:
<?php
$token = "XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXX";
$chat_id = "-XXXXXXXX";
$message = $_GET['message'];
$message_to_telegram = ($message);
$send_to_telegram = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$message}","r");
Add after curl_exec($ch); var_dump(curl_getinfo($ch)); and see what Telegram answers you
1) enable error output
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', '1');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question