How to add line breaks in Telegram bot messages using PHP

I’m working on a PHP Telegram bot and trying to send messages with multiple lines. I’ve tried using "\n" and "\r\n" to create line breaks in my text messages, but instead of actual line breaks, I’m getting underline characters _ showing up in the message.

Here’s my current code:

$message = 'Welcome to our service! We hope you enjoy your stay with us.';
$message .= " \n ";
$message .= 'You will receive daily updates around 8 PM local time.';

The problem is that when the bot sends this message, it doesn’t create a proper line break between the two sentences. Instead, it shows an underscore character where the line break should be. What’s the correct way to format line breaks in Telegram bot messages? Is there a specific method or character sequence that works better for Telegram’s message formatting?

Had this exact problem last month - drove me nuts for hours! The underscore thing happens because Telegram auto-enables some markdown parsing even without setting parse_mode. What fixed it: use double quotes instead of single quotes around the newline character. Try this: ```php
$message = “Welcome to our service! We hope you enjoy your stay with us.\n”;
$message .= “You will receive daily updates around 8 PM local time.”;

Key difference is double quotes with proper \\n escaping. Single quotes in PHP treat \n as literal text, not escape sequences - might be confusing Telegram's parser. Also check your Content-Type header is set to application/json when sending to the Telegram API.

Your underscore issue is likely due to Telegram’s markdown parsing. When you have spaces around your newline like " \n ", Telegram treats underscores differently depending on the parse mode. Remove the extra spaces and use just \n without any whitespace:

$message = 'Welcome to our service! We hope you enjoy your stay with us.';
$message .= "\n";
$message .= 'You will receive daily updates around 8 PM local time.';

Check that you are not specifying a parse_mode parameter in your sendMessage request. If you are currently using ‘Markdown’ or ‘MarkdownV2’, consider either removing the parse_mode or switching to ‘HTML’ mode. Using plain text mode is often more effective for simple line breaks, as it avoids formatting conflicts.

Use double newlines \n\n instead of single ones - they work way better. Also check for weird formatting characters before the linebreak. Copy-pasting code sometimes adds invisible stuff that breaks everything.