Google App Engine with Telegram Bot API through PHP output no whitespace

9 views
Skip to first unread message

tanto259 via StackOverflow

unread,
Oct 1, 2016, 11:30:11 PM10/1/16
to google-appengin...@googlegroups.com

So, I configure my PHP script to send message from my contact form to my telegram chat with a bot.

Here's the PHP script code:

<?php
if(trim($_POST["gotcha"]) !== "") {
  header("Location: https://example.com/");
} else {
  if(isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["subject"]) && isset($_POST["content"])) {

    $wholeMessage = "Name:"." ".$_POST["name"]." "."|"." "."Email:"." ".$_POST["email"]." "."|"." "."Subject:"." ".$_POST["subject"]." "."|"." "."Message:"." ".$_POST["content"];
    $data = "https://api.telegram.org/bot<BOTID>/sendmessage?chat_id=<CHATID>&text=".$wholeMessage;

    $response = file_get_contents($data);

    header("Location: https://example.com/thanks/");
  } else {
    header("Location: https://example.com/");
  }
}
?>

The result on my Telegram chat:

Name:firstname|Email:ma...@mail.com|Subject:test|Message:testhttps://google.commouseappletest

Using %nbsp; only output:

Name:

with nothing else outputted.

As you can see, all the whitespace has disappeared. Is there something wrong with my code?

Thanks



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39813562/google-app-engine-with-telegram-bot-api-through-php-output-no-whitespace

Turtle via StackOverflow

unread,
Oct 2, 2016, 12:20:05 AM10/2/16
to google-appengin...@googlegroups.com

You need a URL Encode.

  • Use %20 as whitespace.
  • Or use urlencode() function to encode your url.

This can also rid your code of the danger of strange errors, especially when you are using a url containing Chinese or other special characters without url encode.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39813562/google-app-engine-with-telegram-bot-api-through-php-output-no-whitespace/39813813#39813813
Reply all
Reply to author
Forward
0 new messages