R
R
Ruslan Tilyaev2020-06-07 18:22:30
PHP
Ruslan Tilyaev, 2020-06-07 18:22:30

Why is a message not sent to telegram via php?

Good day. Faced the problem of sending a message to telegram from the site. The site is made on yii2. The mechanism is like this, a person places an order and a message about a new order comes to the admin in telegrams. Everything works fine on openserver, but when I uploaded it to the hosting, difficulties started (
allow_fopen_url is enabled.
here is the error:

fopen(https://api.telegram.org/bot1235530239:AAEm4k2m3w2xl6GrBdfx_B4PB0PUfLW5nxU/sendMessage?chat_id=-402381614&parse_mode=html&text=Новый заказ!): failed to open stream: Network is unreachable

here is what telegram api says:
{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}

Although I pass all the data;
$token = "**********";
$chat_id = "**********";
$sendToTelegram = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text=Новый заказ!","r");


Please help. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-06-08
@SilenceOfWinter

invalid URI, use http_build_query()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question