473,769 Members | 7,315 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7834
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!
Jan 12 '06 #2
Great - that's it! Thank you very much! :-)

Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2623
by: Jim Seymour | last post by:
I have a contact form that uses PHP's mail() function. It recently came to my attention that (some?) MS-Windows mail servers may not properly process data given to the mail() function that's only newline-terminated. The mail() function takes up to five parameters: mail(recipient, subject, message, ]) The ones of interest here are the first four. The questions are
7
12624
by: Anders S. Clausen | last post by:
Hi I have a jsp with a couple of <HTML:TEXTAREA> where I would like to dynamically size the textarea depending on the length of a String entered on a different jsp. The two new textareas are to display the full text (and no scroll bars), and I was wondering what I set the row and cols to .... keeping in mind that I have the length of the text I want to display. Any ideas??? Cheers.
3
9241
by: stuart | last post by:
I am posting data to a sql server database via an asp web form. When retreiving the data the information is all concatenated on one line i.e. When posting in textarea the format looks like: 1. information 2. information 3. information but when retreiving the data it looks like:
13
21334
Nert
by: Nert | last post by:
hello every one, i need help.. how can i use the mail() funtion in php? when ever i execute the mail function i continuesly receive this error message: what do i need to do in order for me to connect with my localhost mailserver? can anyone help me with this? thanks in advance..(^_^)
2
19218
by: deko | last post by:
I have a feedback form on my website with a textarea for visitors to type comments, etc. Nothing special. When users click the "Send" button, the form posts, and I copy the contents of the textarea to a file like this: $feedback = trim($_POST); $fp = fopen($feedback_file,'a'); fwrite($fp, $feedback); fclose($fp); The problem is the line breaks in the textarea are lost when copied to the file.
3
5672
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to replace spaces with &nbsp;. The <br> part works well enough, but I keep getting "%20" instead of "&nbsp;" for the spaces. I understand that escape() changes " " to "%20", but I would think the ConvertSpaces function below would change the %20 to...
5
3029
by: Icarus - iD_Ten_T helper | last post by:
First of all, my apologies if this should be in a php newsgroup and not here, but I thought this the best place to start. I want to parse the text from a <textareaform element but when I pass this in a POST request to the server and then output it using PHP, all formatting is gone. I was under the impresssion that the textbox would register any carriage returns or line breaks and send them in the final text for processing?
3
1964
sanjay123456
by: sanjay123456 | last post by:
Dear friends, <?php //define the receiver of the email $to = 'sanjay.mit@gmail.com'; //define the subject of the email $subject = 'Test HTML email'; //create a boundary string. It must be unique
2
3689
by: robin1983 | last post by:
Dear All, Firstly I would like thank all senior and junior who helping and sharing the knowledge to us. Actually, I have a small query. The problem is that I have a form which have only two field. first one is Text Field and the second one is TextArea. What ever I faced the value from Database (mysql) entered through the TextArea field, the content are showing in the not the format which I entered. The line are not breaking as it was....
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.