我使用PHP表單作爲我的網站的一部分讓人們聯繫。表單會將結果發佈到另一個網頁。目前,測試它只是簡單的,但它將被密碼保護。但它不一定是安全的,這不是一個商業的事情,只是一個項目。 表單代碼:PHP聯繫表格和發帖
<form action="contactform.php" method="post">
<p><label>Name: <input name="name" placeholder="eg: John Doe"></label></p>
<p><label>Subject: <input name="subject" required placeholder="eg: App Updates?"></label></p>
<p><label>Content: <input name="content" required placeholder="eg: When will the next update to your app be released?"></label></p>
<p><label>Email Address: <input name="email" required placeholder="eg: [email protected]" type="email"></label></p>
<p><button input type="submit">Submit form</button></p>
</form>
PHP代碼:
<?php
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$subject = htmlspecialchars($_POST['subject']);
$content = htmlspecialchars($_POST['content']);
echo $name, $email, $subject, $content;
$text = "NAME: $name <br>
EMAIL: $email<br>
SUBJECT: $subject<br>
CONTENT: $content<br><br><br>";
$file = fopen("formresults.html","a+");
fwrite($file, $text);
fclose($file);
?>
我不知道爲什麼它不只是張貼,每當我在瀏覽器中測試它,它只是下載PHP頁面
這是您的第一個php代碼?你的http服務器被配置爲處理php文件?在瀏覽器中,通過'file://'或'http://'語法加載腳本? – fusion3k