title: Error in sending mail from php file
body: <p>I'm pretty new to using php and I'm currently trying to set up a personal site. I've got a contact form in the page at the bottom that I can't seem to get to work and send myself an email of the message the client writes. The form has the following html: </p>
  
  <pre><code>    &lt;form method="post"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="name"&gt;Your name:&lt;/label&gt;
                      &lt;input type="text" id="name" class="form-control" placeholder="Your name" /&gt;
  
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="email"&gt;Your email:&lt;/label&gt;
                      &lt;input type="email" id="email" class="form-control"   placeholder="Your email"/&gt;
  
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for="comment"&gt;Message&lt;/label&gt;
                      &lt;textarea class="form-control" id="comment"&gt;&lt;/textarea&gt;
  
                  &lt;/div&gt;
                  &lt;input type="button" class="btn btn-warning" value="submit" id="sendEmail"/&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>and I'm using the to following JavaScript to put the form into a php file and send out an email to myself. Here in the JavaScript:</p>
  
  <pre><code>&lt;script&gt;
  $(".contentContainer").css("min-height",$(window).height());
  
  $("result").hide();
  
  $("#sendEmail").click(function(){
  
      var name = $("#name").val();
      var email = $("#email").val();
      var comment = $("#comment").val();
  
      $.post("validate.php",
      {postname:name,postemail:email,postcomment:comment},
      function(data){
  
          $("#result").html(data).fadeIn();
      });
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>and here is the php file that I'm using: </p>
  
  <pre><code>    &lt;?php
  $error = NULL;
      if (!$_POST['postname']) {
          $error="&lt;br /&gt;Please enter your name";
      }
      if (!$_POST['postemail']) {
          $error.="&lt;br /&gt;Please enter your email address";
      }
      if (!$_POST['postcomment']) {
          $error.="&lt;br /&gt;Please enter a comment";
      }
      if ($_POST['postemail']!="" AND !filter_var($_POST['postemail'], FILTER_VALIDATE_EMAIL)) { 
          $error.="&lt;br /&gt;Please enter a valid email address";
      }
      if($error !=NULL){
          $result='&lt;div class="alert alert-danger"&gt;&lt;strong&gt;There were error(s)
          in your form:&lt;/strong&gt;'.$error.'&lt;/div&gt;';
      } else{
          if (mail("PERSONAL EMAIL", "Comment from website", "Name: ".$_POST['postname ']."
          Email: ".$_POST['postemail']." 
          Comment: ".$_POST['postcomment'])) {
  
              //echo $_POST['postname']
  
              $result='thank you!';
          } else{
              $result='There was an error sending your message! Try again later!';
          }
      }
  ?&gt;
  </code></pre>
  
  <p>A couple of things I've noticed: when I replace the 'PERSONAL EMAIL', I don't receive an email when I test out the contact form on my website. However, when I uncomment the echo $_POST['postname'] right after the mail statement (I interpreted it as mail=true so mail sent) then the variable echos back to my website. However, the $result variable doesn't appear in the #result div like I intend. What am I dong wrong? Is there an error I've made that I need to know for future reference? This concept between html &lt;-> php is still kind of new to me! </p>