I have the following PHP code with the parse_mode=MarkdownV2 and it isn’t posting to the channel I have it linked to. I verified this works, because if I remove the parse_mode it will post to the channel. Do I have some type of formatting error before sending this to the telegram bot?
$realurl = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$encoded = urlencode($realurl ." n**". $obj->region .' - '. $obj->org .'** - '. $_SERVER['REMOTE_ADDR'] .' Referrer: '. $_SERVER['HTTP_REFERER'] );
file_get_contents($api_path."/sendmessage?chat_id=-152445&parse_mode=MarkdownV2&disable_web_page_preview=1&text=$encoded");
2
Answers
Reason why it doesn't work is because you need to escape the following characters: . - _
This is the error message you get if you submit a message with . in it:
The Telegram MarkdownV2 Docs shows the following example for bold text:
Your code shows:
So you open and close the bold tag right away, therefore nothing is shown in bold.
You need to use a single
*
instead off the double**
!