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

  • SEARCH
  • Home
  • 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 8677991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:36:07+00:00 2026-06-12T20:36:07+00:00

My php form which saves the output in a text file glues the result

  • 0

My php form which saves the output in a text file glues the result to one string like:

Name1Email1The Message1Name2Email2The Message2Name3Email3The Message3Name4Email4The Message4

But I need spaces and/or newlines. I normaly don’t use PHP so I don’t get it. I did’t find an answer on the web, also read some Q/A here, but this didn’t help me.

The Form:

<form action="mailer.php?savedata=1" method="post">
Your Name: <input type="text" name="name"><br>
Your Email: <input type="text" name="email"><br>
Your Message:<br> <textarea name="message" rows="5" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

The PHP

<?php
$savedata = $_REQUEST['savedata'];
if ($savedata == 1){ 
$data = $_POST['name'];
$data .= $_POST['email'];
$data .= $_POST['message'];
$file = "YOURDATAFILE.txt"; 

$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
echo "Your Form has been Submitted!";

}
?>
  • 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-06-12T20:36:08+00:00Added an answer on June 12, 2026 at 8:36 pm

    As other answers state, you need to add in an end of line character after each field.

    Different OS’s use different line endings, though, and so a “\n” may not display as a new line on Windows, for example. As Mahdi said, you can use Windows style “\r\n” line endings, or you can use the PHP_EOL constant so that line endings appropriate to the server will be output, in which case your code would look like

    $data = $_POST['name'] . PHP_EOL;
    $data .= $_POST['email'] . PHP_EOL;
    $data .= $_POST['message'] . PHP_EOL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a form which has 3 text inputs and one file input.
I have a php form which saves these values to the database: id rand
i have an form which will send some data to an php file ,
I have a php file that contains a form (which contains 2 input boxes
I have a form in html which runs a php script whitch inserts text
I'm sending a form to a php page, which then saves to a mysql
I have created a PHP form which requires the user to select a postcode
I added a drop down to a PHP contact form which pops up in
I managed to develop a PHP authentication/activation form which works fine for what I
Language: PHP I have a form which asks users for their educational details, course

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.