Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Text Area using mail( ) 2

Status
Not open for further replies.

Muppsy007

Programmer
Apr 4, 2003
98
NZ
Hi all,

I have a contact page where people can email me by filling out a form, including a large text area which contains the actual message. This page is contact.php

When the user submits, the form action takes them to contact_confirm.php which has a thankyou message and includes a simple script called gen_email.php.

gen_email.php simply populates variables with the form elements from contact.php and sends them via the mail() function.

When I get the email, all is fine, except all carriage returns the user entered in the message text area are ommited, so the message just appears as a continuous paragraph. It also has trouble with some characters like ', making them appear as /'.

Is there any way of fixing this before the mail is sent?

Thanks in advance
 
It sounds like something is happening to the new line characters...

In text boxes, a new line is \r\n

Ensure that nothing is changing the message before it's submitted. For example, try

$message = str_replace("\r\n","NEW LINE",$message);

then print that on the screen. If those marks aren't there...you won't see any 'NEW LINE' comments, thus you know something is removing them.

When I have my textboxes create email, I don't have wrap or anything...

<textarea name=message>write your message</textarea>

then on the mail page:

$message = $_POST['message']; // or $_GET['message'];
mail($to,$subject,$message);

If it's that simple, the new lines should show up.

Try posting your code here, we can take a look
 
Thanks alot guys.

JWOODS7, your little string replace tip made me come across the conclusion. The new lines were definately still getting through (as they were replaced by "NEW LINE").

The thing was I was trying to send the message in HTML format, making \r\n obsolete I guess.

So I just modified your code to read:
$message = str_replace("\r\n","<BR>",$message);

And all is well!

Thanks again
Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top