So im trying to make my form work, but it doesn't seem to be possible.
i've included the php script into the index.php :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Andrewch';
$to = 'adreasch@gmail.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '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'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}?>
And the html looks like this
<form method="post" action="" >
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2?</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="">
It just keeps me redirecting to top, it is not even write the success text.
What am i doing wrong?
P.s: Web hoster let me use PHP.
in
<form method="post" action="" onSubmit="window.location.reload()">
you need to put the site it's on like example.com/mail.phpNotice: just something the found my eye is the second > on the form in html in the end of your
<form>
tagIn Form action give same page name to redirect same page and submit page value also like below
i hope this help you
Remove this part it couses to lose the
$_POST
values.onSubmit="window.location.reload()"
You don't have a input field for human so that
$_POST
is never set.