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
You need a URL Encode.
%20 as whitespace.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.