我将输出保存在文本文件中的 php 表单将结果粘合到一个字符串,例如:
Name1Email1The Message1Name2Email2The Message2Name3Email3The Message3Name4Email4The Message4
但我需要空格和/或换行符。我通常不使用 PHP,所以我不明白。我没有在网上找到答案,也在这里阅读了一些 Q/A,但这对我没有帮助。
表格:
<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>
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!";
}
?>