0

Can anyone tell me why no matter what, when submitted, my message comes back false? Im bad at coding but this seemed easy enough, maybe I missed something obvious?

<?php
$name = $_POST['name']; //Grabs what is typed in the name box
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Rissotos'; //Will say where the email is coming from
$to = 'myemail@gmail.com'; //where the email is being sent
$subject = 'Rissotos Message';//Built in subject Line

 $body = "From: $name\n E-Mail: $email\n Message:\n $message";//Store all Variables
?> 

<?php
if ($_POST['submit'] && $human =='checked') {//checks spam 
if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';//Message if all is filled out 
} else { 
    echo '<p>Something went wrong, go back and try again!</p>';//Message if something was not filled out properly 
}
}else if ($_POST['submit'] && $human !='checked') {
echo '<p>No  Robots Allowed!</p>';
} 

?>

<form method="post" action="contactUs.php">

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

        <p> By checking this box, you validate that you are not a Robot.</p>
        <input name="human" type="checkbox" value="checked" />

        <input id="submit" name="submit" type="submit" value="Submit">

    </form>

The first bit of php is just for the email to be built and I dont think it is the problem. Im not sure if there is a problem with how the check box named "human" is being called or if the "checked" for the boxes value is giving the issue.

Andrew
  • 49
  • 2
  • 7
  • Why do you think an `` spawns a variable `$human` in your script when no other `` works that way? – deceze Apr 19 '17 at 15:40
  • 1
    And where is `$human` created? – JustOnUnderMillions Apr 19 '17 at 15:40
  • classic undefined – Funk Forty Niner Apr 19 '17 at 15:40
  • 1
    Read about http://php.net/manual/en/security.globals.php and You will see, why `$human` is not set even when You check it. – Roman Hocke Apr 19 '17 at 15:40
  • it's because `$human` is no where defined. write `$human = $_POST['humen'];` on top. Also wrap your php code in side `if(isset($_POST['submit'])){..}` – Alive to die - Anant Apr 19 '17 at 15:41
  • 1
    Note: A good `bot` will check this checkbox! Did you know capcha or else? – JustOnUnderMillions Apr 19 '17 at 15:42
  • Because Im new and I dont know what Im doing. I thought human was created when I defined input name as "human" in the checkbox. Is there some other way to call that checkbox or something else that I should be naming it? – Andrew Apr 19 '17 at 15:43
  • Bind it like the other: `$human = $_POST['human'];` 8-] – JustOnUnderMillions Apr 19 '17 at 15:44
  • @Andrew ... not since the dark, dark days of `register_globals` : http://stackoverflow.com/questions/3593210/what-are-register-globals-in-php ... as an aside, what you're trying to create is called a *honeypot* http://stackoverflow.com/questions/3622433/how-effective-is-the-honeypot-technique-against-spam – CD001 Apr 19 '17 at 15:45
  • @JustOnUnderMillions Thanks, it works now! Sorry for the noob question cause I know this is a fairly simple task. Moving past HTML and CSS definitely makes you think a bit more when adding functionality. – Andrew Apr 19 '17 at 15:58
  • Thank you everyone who aided! – Andrew Apr 19 '17 at 15:59

0 Answers0