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_lineb reaks($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_lineb reaks($_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!