我想創建一個簡單的聯繫頁面,但是當我提交表單時,它會將我導向空白頁contact-form.php。我用這篇文章作爲參考:http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/ 我在做什麼錯?聯繫表格不工作?
代碼上的index.php(拐角的div純粹是爲了造型的目的)
<form action="contact-form.php" method="post" autocomplete="off" id="contact">
<div class="corner"></div>
<input type="text" required name="name" placeholder="Name" value="">
<div class="corner"></div>
<input type="text" required name="email" placeholder="Email" value="">
<div class="corner"></div>
<input type="text" required name="check" placeholder="Question of the day: What's 2 + 2 ?" value="">
<div class="corner"></div>
<textarea name="message" rows="25" cols="50" placeholder="Drop me a line!"></textarea>
<button class="send" type="submit" name="submit">Send</button>
</form>
代碼上接觸form.php的
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: MessageAnita';
$to = '[email protected]';
$subject = 'Hello';
$check = $_POST['check'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $check == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $check != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
你有錯誤報告打開? –
從輸入中刪除空值'value =「」',不需要它們。 – mdesdev
你的其他和其他如果語句應該改變 – tarzanbappa