• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

formatting of text area in php mail

Hi All,

We have a form text area field below, but when we process the code, the body of the email does not appear the way it was entered in the form.

It should appear with line breaks, but instead it appears as one line of text.

Should appear like :

Hi Client,

Thanks for the meeting today.

Regards.


But appears like

Hi Client, Thanks for the meeting today. Regards.

<textarea cols="45" rows="9" name="email_message_one">This message will go to the client.</textarea>

Open in new window


Header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Open in new window


if (!isset($_POST['email_message_one']))  $email_message_one = ''; else $email_message_one = $_POST['email_message_one'];

Open in new window


Email body
$email_message_one

Open in new window


Any help would be appreciated.
0
Cheryl Lander
Asked:
Cheryl Lander
  • 2
2 Solutions
 
Loganathan NatarajanLAMP DeveloperCommented:
Please use nl2br() function while you attach with email body.
0
 
Dave BaldwinFixer of ProblemsCommented:
How are you entering it in the form?  If you press 'enter' while you are in a form, it will submit the form, not create a line break.
0
 
Cheryl LanderAuthor Commented:
We have tried just hitting enter for each line, also by hitting Shift + Enter.

Same results.

All text comes out as one line.

We have looked into the suggestion that Loganathan has provided but are having trouble implementing it.
0
 
Dave BaldwinFixer of ProblemsCommented:
Your are dealing with conflicting methods.  Plain text uses "\r\n" for line breaks while HTML uses <br> and ignores \r\n in the text.  Depending on your situation, you might be able to use nl2br to put the text into a variable that will then have <br> instead of \r\n.  Then you could include that in your message body.

A good test is to echo the message to the screen.  HTML with <br> in the right places will look correct.  Plain text with \r\n will look right if it is enclosed between <pre>text</pre> tags.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now