我想创建一个简单的联系页面,但是当我提交表单时,它会将我导向空白页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