This is a discussion on When text string is mailed, extra line breaks are introducd within the PHP Language forums, part of the PHP Programming Forums category; Hi all, I have the following message string: $message = <<<EOT Personal Information: Name: {$_POST["name"]} ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
I have the following message string: $message = <<<EOT Personal Information: Name: {$_POST["name"]} Address: {$_POST["address"]} EOT; Now, when I echo this to the browser, (and view the source), it is exactly what you would expect. Three lines of information. However, if I use mail() or the PEAR Mail class to send $message via email, I get an extra line break at the end of every line. What in the world would cause this? Any ideas? -Josh |
|
|||
|
Joshua Beall wrote:
> I have the following message string: > > $message = <<<EOT > Personal Information: > Name: {$_POST["name"]} > Address: {$_POST["address"]} > > EOT; Try this instead: $message = "Personal Information\n Name: {$_POST[name]}\n Address: {$_POST[address]}"; > Now, when I echo this to the browser, (and view the source), it is exactly > what you would expect. Three lines of information. However, if I use > mail() or the PEAR Mail class to send $message via email, I get an extra > line break at the end of every line. What in the world would cause this? > Any ideas? I'm betting on a few "\r" in the middle of the message being converted to "\n". HTH -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |
|
|||
|
"Pedro" <hexkid@hotpop.com> wrote in message news:bmn5ef$om59s$1@ID-203069.news.uni-berlin.de... > Try this instead: > $message = "Personal Information\n Name: {$_POST[name]}\n Address: {$_POST[address]}"; That is the workaround that I have been using. I was just hoping there another way. > I'm betting on a few "\r" in the middle of the message being > converted to "\n". Ah, of course, that would make perfect sense. I bet every line is getting \r\n at the end of it when PHP stores the string. I suppose I could just do a string replace to strip out all the \r characters. Oh well. Thanks! -Josh |
|
|||
|
Joshua Beall wrote:
> Ah, of course, that would make perfect sense. I bet every line is getting > \r\n at the end of it when PHP stores the string. I suppose I could just do > a string replace to strip out all the \r characters. Oh well. Removing all "\r"s might not be such a good idea ... some OS's use it as the line break character. The ones I know of are: Un*x \n DOS/Win \r\n Macintosh \r Expecting only these and assuming the user will not type the character with code zero, I do: <?php $input = $_POST['textarea']; $input = str_replace("\r\n", "\x00", $input); $input = str_replace("\r", "\x00", $input); $input = str_replace("\x00", "\n", $input); ?> -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |