By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,050 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,050 IT Pros & Developers. It's quick & easy.

When text string is mailed, extra line breaks are introducd

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jul 17 '05 #2

P: n/a

"Pedro" <he****@hotpop.com> wrote in message
news:bm************@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
Jul 17 '05 #3

P: n/a
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.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.