Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:35:56+00:00 2026-05-27T21:35:56+00:00

I have a <textarea> in a form for user comments, and when the contents

  • 0

I have a <textarea> in a form for user comments, and when the contents are passed to form mail, the line breaks are being converted to spaces. How can I preserve the line breaks that the form’s user types in?

relevant php:

$comments = $_REQUEST['comments'];
// This grabs the comments from the submitted form

//...

$to = $configEmail;

$subject = "Website Order Received: $offer";

$contents = "blah blah blah...";
if (!empty ($comments)) {
    $contents = $contents."\nComments: $comments\n\n";
}

//...

mail($to, $subject, $contents);

And in the HTML end of the form… (the comments are put into the form if it’s submitted with errors, so data isn’t lost)

<label>Comments / Questions</label>
<textarea name="comments"><?php echo $comments; ?></textarea>

If I type:

line 1
line 2
line 3

It remains like that if the form is submitted with errors, so $comments = $_REQUEST['comments']; is definitely preserving the line breaks. But the plain-text e-mail gives me:

line 1 line 2 line 3

How can I preserve the line breaks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:35:57+00:00Added an answer on May 27, 2026 at 9:35 pm

    The problem is the line breaks coming from the textarea are \n not <br>..
    So replace the \n by <br> before sending the mail..

    $body= str_replace("[enter]", "\n",$body);
    

    Rember user double quoutes in “\n”…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a textarea that can contain large amounts of content
I have a form with a <textarea> and I want to capture any line
Assuming we have a comment textarea where the user can enter this code: [quote=comment-1]
I have a feedback form where the user can enter his/her feedbacks in a
I have made a textarea form where you can change your description and like
I have an input form with two textareas allowing a user to type in
Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
I have a form with a textarea. Users enter a block of text which
I have an html form where the width of a textarea is specified with
I have textarea in my site(link shortening site) i want to user enter some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.