contact form in HTML and PHP

Asked

Viewed 358 times

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 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 changed the email here, but the email I am using is a valid email. When I click submit, I get the message that the message was successfully sent, but the reality is that I am not receiving anything in my email. Any suggestions? Thank you

  • Basic question: have you checked your email spam box? And there is no field in the form called human, what would that be?

  • was the first thing I did!

  • does so, comments //$Human = $_POST['Human']; and puts below it $Human = 4; and see if you receive email in your box

  • Voce suggests that I eliminate $Human = $_POST['Human']; and replace it with $Human = 4?

  • no, he comments it with two bars /$Human = $_POST['Human']; and puts below it $Human = 4;

  • I will have to give a way out, but I left an answer. Don’t forget to uncomment $Human = $_POST['Human'] and elimibar $Human = 4;

  • I made an edit in the reply explaining what was happening in your code

Show 2 more comments

1 answer

0


PHP is requesting a value from a Human field

$human = $_POST['human'];

Only this field in your HTML does not exist

So add a field in your HTML with Human name as an example

<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>
  • didn’t work :s

  • Thank you very much worked. so for what I understand is that it was missing to put the check in HTML is this? I appreciate you explaining, now it’s working, which is great, but I need to understand.Thanks again, thank you

  • I made an edit in the reply explaining what was happening in your code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.