如何从表单中读取数据


How to read data from a form?

我有一个php脚本,它将使我的电报机器人发送一条消息:

<?php
$botToken = "<my_bot_token_here>";
$website = "http://api.telegram.org/bot".$botToken;
$chat_id = 25665198;
file_get_contents($website.'/sendmessage?chat_id='.$chat_id.'&text='.$_POST["message"]);

我想决定将发送什么消息,所以我创建了一个表单:

 <form action="telegram.php" method="post">
     Message: <input type="text" name="message" />
     <input type="submit">
  </form>

但由于某种原因,脚本不起作用。怎么了?

也许只是https而不是http on $website。所以把它改成:

$website = "https://api.telegram.org/bot".$botToken;
此外,将

最后一行更改为如下所示:

$output = file_get_contents($website.'/sendmessage?chat_id='.$chat_id.'&text='.$_POST["message"]);
if($output == false) ? echo "Something gone Wrong" : echo $output;

通过这种方式,您将看到 file_get_contents() 的结果