Jump to content


Photo

Line Breaks - Mail \r\n not working


  • Please log in to reply
2 replies to this topic

#1 chrispols

chrispols
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 17 October 2006 - 08:42 AM

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.

#2 chrispols

chrispols
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 17 October 2006 - 09:15 AM

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

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 17 October 2006 - 09:42 AM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users