Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

html - Cannot POST /contact.php

I have a contact form on my website and I get the "Cannot POST /contact.php" error.

This is my form at html page:

<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>

And then I tried my PHP code (contact.php). I don't know if there is something wrong as I am very bad at PHP:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '[email protected]';
$subject = $_POST['subject'];
$human = $_POST['human'];

$body = "From: $name
 E-Mail: $email
 Message:
 $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>';
}
?>

If anyone who understands PHP could help, that would be amazing.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As said by Sakthi Karthik, you need to check the directory/path of contact.php.

Also in the condition you should check:

if(isset($_POST['submit'] && $human == '15')

Likewise:

else if(isset($_POST['submit'] && $human != '15')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...