I have written some PHP code for a contact form for my one page portfolio, when it is submitted it just opens up a blank page and also the e-mail isnt sent and the text is not echo'd out. I am not very confident with PHP as it is fairly new to me. if anyone could help that would be great?
html -
<form id="cont-form" method="post" action="mail.php">
<fieldset>
<legend>Send me a message</legend>
<ol>
<li>
<label for="name">Name</label>
<input id="name" name="name" type="text" placeholder="First and last name" required autofocus>
</li>
<li>
<label for="email">Email</label>
<input id="email" name="email" type="email" placeholder="example@domain.com" required>
</li>
<li>
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel" placeholder="Eg. 07500000000" required>
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" type="text" placeholder="What the message is about" required>
</li>
<li>
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Insert your message or question here" rows="10" cols="50">
</textarea>
</li>
<li>
<label for="human">What is 2 + 2 ?</label>
<input id="human" name="human" type="number" placeholder="Please insert answer" required>
</li>
</ol>
</fieldset>
<fieldset>
<input class="button" id="submit" type="submit" value="Send it!">
</fieldset>
</form>
php -
<?php
$name = $_POST['name']; //'name' has to be the same as the name value on the form input element
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: $email';
$to = 'ben_humphries@hotmail.co.uk'; //set to the default email address
$subject = $_POST['subject'];
$human = $POST['human'];
$body = "From: $name
E-Mail: $email
Message:
$message";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) { //mail sends it to the SMTP server side which sends the email
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>";
}
?>