I’m working on a PHP application that sends messages through the Telegram bot API. My current implementation works fine for basic text formatting like bold, italic, and underline styles. However, I’m running into problems when trying to send messages that contain accented characters such as à, è, é, ì, and ù.
Had the same issue when I built my first Telegram bot last year. It’s usually a character encoding mismatch between your PHP script and the HTTP request to Telegram’s servers. First, make sure your PHP file is saved as UTF-8 without BOM. Most editors default to other encodings that mess up special characters before they even hit your cURL request. Second, add this Content-Type header to your cURL request: curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘Content-Type: application/x-www-form-urlencoded; charset=utf-8’)); If you’re storing messages in a database first, check that your collation supports UTF-8. I use utf8mb4_unicode_ci since it handles all Unicode characters and emojis. Those changes should fix the accented character display in your Telegram messages.
Check if you’re using mb_convert_encoding before sending text to Telegram. I had the same issue with Italian characters in a news bot I built two years back. Usually it’s mixed encoding in your data pipeline, not just the HTTP request.
Try this: wrap your content variable with $content = mb_convert_encoding($content, 'UTF-8', 'auto'); before adding it to the params array. Also make sure any text processing functions handle multibyte characters. Don’t use substr - it’ll break UTF-8 sequences. Use mb_substr instead.
If you’re pulling content from files or external sources, double-check they’re UTF-8 encoded too. Telegram’s API expects proper UTF-8, so any corruption before your cURL request shows up as garbled text in messages.
Check your server’s locale settings too. The problem might not be your code - could be PHP’s default charset config. Try adding ini_set('default_charset', 'utf-8'); at the top of your script and see if that fixes the accented characters.