提交表單時,我得到一個404頁面。有些東西缺失或錯誤。 這是一個wordpress網站。我在wordpress的選項中插入了電子郵件,沒有發生任何事情。我看到了很多堆棧溢出的問題,但沒有人幫助我。我不想使用插件。聯繫表單不起作用
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" value="">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="email" class="form-control" id="email" name="email" placeholder="[email protected]" value="">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" rows="4" name="message" placeholder="Message..."></textarea>
</div>
<br/>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">2 + 3 = ?</span>
<input type="text" class="form-control" id="human" name="human" placeholder="">
</div>
<br/>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-5">
<input id="submit" name="submit" type="submit" value="Enviar" class="btn btn-button">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<! Will be used to display an alert to the user>
</div>
</div>
</form>
PHP代碼:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Contact Form';
$to = '[email protected]';
$subject = 'Contact ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
然後'contact.php'不存在 – RiggsFolly
是的存在,它在同一個文件夾中。但我猜這個表格不能取他。你有什麼想法,爲什麼? – APDB
是正確的嗎? * NIX系統上的'contact.php'!= Contact.php' – RiggsFolly