我的网站上有联系表格,我收到“无法POST /contact.php”错误。
这是我在html页面上的表格:
<form role="form" action="contact.php" method="post">
<div class="form-group">
<label for="InputName">Nom</label>
<div class="input-group">
<input type="text" class="form-control" name="name" id="InputName" placeholder="Nom" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
</div>
</div>
<div class="form-group">
<label for="InputEmail">Email</label>
<div class="input-group">
<input type="email" class="form-control" id="InputEmail" name="email" placeholder="Email" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
</div>
</div>
<div class="form-group">
<label for="InputEmail">Sujet</label>
<div class="input-group">
<input type="text" class="form-control" id="InputEmail" name="subject" placeholder="Sujet" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
</div>
</div>
<div class="form-group">
<label for="InputMessage">Message</label>
<div class="input-group">
<textarea name="message" id="InputMessage" class="form-control" rows="5" required></textarea>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
</div>
</div>
<div class="form-group">
<label for="InputReal">5 + 10? (Spam Checker)</label>
<div class="input-group">
<input type="text" name="human" class="form-control" name="InputReal" id="InputReal" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
</div>
</div>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-left">
</form>
然后我尝试了我的PHP代码(contact.php)。因为我在PHP上非常糟糕,我不知道是否有什么问题:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'myemail@email.com';
$subject = $_POST['subject'];
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '15') {
if (mail($to, $subject, $body)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '15') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
如果了解PHP的人可以提供帮助,那就太棒了。
提前致谢。
答案 0 :(得分:1)
正如Sakthi Karthik所述,您需要检查contact.php
的目录/路径。
同样在这种情况下你应该检查:
if(isset($_POST['submit'] && $human == '15')
同样地:
else if(isset($_POST['submit'] && $human != '15')
答案 1 :(得分:0)
确保您在同一文件夹中有contact.php
个文件。
您缺少标记</form>
答案 2 :(得分:0)
确保您正在XAMP / htdocs /“您的项目文件夹” /contact.php中运行网页
PHP是一种服务器端语言,它需要在服务器上运行。
启动XAMPP,并确保Apache和MySQL已启动并运行。