468,272 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

html textarea --> php mail function produces additional line break

Hi,

I'm reading text from a html textarea field (standard wrap
functionality, no value specified). If I display it via nl2br() (after
html form submission), everything's ok. But if I send it via mail() the
receiver gets each single line break (originating from textarea)
displayed by TWO line breaks. So the text needlessly gets inflated...
Can anybody help me out what to do to handle this problem?

Thanks in advance!

Regards,
Christian Schinzel

(copied from php.general)

Jan 12 '06 #1
2 7580
Chris Schinzel wrote:
I'm reading text from a html textarea field (standard wrap
functionality, no value specified). If I display it via nl2br() (after
html form submission), everything's ok. But if I send it via mail() the
receiver gets each single line break (originating from textarea)
displayed by TWO line breaks. So the text needlessly gets inflated...
Can anybody help me out what to do to handle this problem?


Different clients will send line breaks differently:

un*x -- \n
mac -- \r
win -- \r\n
??? -- ???

So normalize input before anyhting else.

<?php
function normalize_linebreaks($text) {
$text = str_replace("\r\n", "\n", $text); /* win -> un*x */
$text = str_replace("\r", "\n", $text); /* mac -> un*x */
return $text;
}

mail($recipient, $subject, normalize_linebreaks($_POST['text_area']));
?>
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 12 '06 #2
Great - that's it! Thank you very much! :-)

Jan 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jim Seymour | last post: by
7 posts views Thread by Anders S. Clausen | last post: by
3 posts views Thread by stuart | last post: by
2 posts views Thread by deko | last post: by
5 posts views Thread by Icarus - iD_Ten_T helper | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.