contact form in HTML and PHP

0

I created a contact form in HTML:

<form id="contactform" method="post" action="contact_form.php">
<h3> Get in touch</h3>
    <h4> Fill in the form below, and we'll get back to you as soon as possible</h4>

<label>Name</label>
<input name="name" placeholder="Type here" required>

<label>Email</label>
<input name="email" placeholder="Please enter your email address" required>

    <label>Message:</label>
    <textarea name="message" placeholder="Type here" required></textarea>

<input id="submit" name="submit" type="submit" value="submit">
    </form>

And then I did post to a PHP page:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: galaxybooks'; 
    $to = '[email protected]'; 
    $subject = 'contact';
    $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>';
    }
?>

For privacy reasons, I've changed the email here, but the email I'm using is a valid email. when I click submit, I receive the message that the message was sent successfully, but the reality is that I am not receiving anything in my email. Any suggestion? Thanks

    
asked by anonymous 20.04.2017 / 18:47

1 answer

0
  

PHP is requesting a value from a field of name human

$human = $_POST['human'];
  

Only this field in your HTML does not exist

So add a field in your HTML with name human like

<h3>I'm not a robot. 2 + 2 is</h3>
<input name="human" placeholder="Type here" required>

HTML

  <form id="contactform" method="post" action="contact_form.php">
    <h3>I'm not a robot. 2 + 2 is</h3>
    <input name="human" placeholder="Type here" required>

    <h3> Get in touch</h3>
    <h4> Fill in the form below, and we'll get back to you as soon as possible</h4>

    <label>Name</label>
    <input name="name" placeholder="Type here" required>

    <label>Email</label>
    <input name="email" placeholder="Please enter your email address" required>

    <label>Message:</label>
    <textarea name="message" placeholder="Type here" required></textarea>

    <input id="submit" name="submit" type="submit" value="submit">
</form>
    
20.04.2017 / 19:31