Jump to content

Archived

This topic is now archived and is closed to further replies.

chrispols

Line Breaks - Mail \r\n not working

Recommended Posts

Hi,
I've been looking all around but can't find exactly how to fix adding line breaks into my automated mail. Can someone tell me what to do to modify this code to get line breaks in.

<?php
$to      = $_POST['Email'];
$subject = 'This is the subject';
$message = 'Hello, this is an automated "\r\n" message <br> new line and text \r more line \r\n and another line';
$headers = 'From: admin@site.com' . "\r\n" .
  'Reply-To: admin@site.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

All I ever get is the actual \r \r\n "\r\n" in my mail..

Thanks a lot.

Share this post


Link to post
Share on other sites
Hi, found the problem.
I had to change
$message = 'Hello, this is an automated "\r\n" message
new line and text \r more line \r\n and another line';
to
$message = "Hello, this is an automated \n\nmessage
new line and text \r more line \r\n and another line";

and it works.. just the double quotes.
Thanks
Chris

Share this post


Link to post
Share on other sites
The reason for this is because everything between single-quotes is interpreted as a literal string, and not interpolated by php as it would be if it were enclosed in double-quotes.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.