我有一個通過php文件向電子郵件發送信息的表單。如何將數據從HTML/PHP表單保存到文本文件
我的HTML形式如下:
<form method="post" action="start-project.php">
<fieldset>
<span><input type="text" name="name" id="name" placeholder="Your Name" required/></span>
<span><input type="email" name="email" id="email" placeholder="Email Address" required/></span>
<span><input type="text" name="phone" id="phone" placeholder="Phone Number" required/></span>
<span><input type="text" name="website" id="website" placeholder="Website (Optional)" /></span>
</fieldset>
<span><input type="submit" name="submit" value="GET STARTED"></span>
</form>
和我的PHP代碼如下:
<?php
$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "Submission: Start a Project";
$name = Trim(stripslashes($_POST['name']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
$website = Trim(stripslashes($_POST['website']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $website;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
我怎麼能有所輸入的數據是在一個文本文件保存在服務器上? 我看過幾篇文章,但我不知道如何用我的代碼實現它。
我很感激任何幫助。
就更不用說了,它的工作原理和發送電子郵件。我只是想要這個額外的選項將條目保存在文本文件中。 –