title: Sending email through Ajax
body: <p>I am using the validate plugin for a form. 
  I just want a contactform with no refresh. I guess it is possible.</p>
  
  <p>This is my Javascript:</p>
  
  <pre><code>$().ready(function() {
  // validate the comment form when it is submitted.
  
   $("#actualForm").validate({
  focusInvalid: false,
  onkeyup: true,
      rules: {
      // simple rule, converted to {required:true}
          name: "required",
          comment: "required",
          email: {
            required: true,
            email: true
          },
      },
  
  submitHandler: function(form) {   
              var name = $('input[name="name"]').val();
              var email = $('input[name="email"]').val();
              var comment = $('input[name="comment"]').val();
              var params = {
                  "name": name,
                  "email": email,
                  "comment": comment,
              };
  
              console.log(data);debugger;
              $.ajax({
              url: 'email.php',
              data: params,
              type: 'POST',
              dataType: json,
              success: function (data) {
  
                  if (data.status) {
                      //Give success log to user
                  } else {
                      //Do something
                  }
              }
              });
          } 
  </code></pre>
  
  <p>And this is my PHP:</p>
  
  <pre><code>&lt;?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $comment = $_POST['comment'];
  $to = 'myemail';
  $from = $email;
  $subject = 'subject';
  $body = "Hello Admin&lt;br&gt;&lt;br&gt;
          Name: &lt;strong&gt;$name&lt;/strong&gt;&lt;br&gt;
          Email: $email&lt;br&gt;
          Bericht: $comment&lt;br&gt;
              ";
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= "From: $from";
  $ok = mail($to, $subject, $body, $headers);
  if($ok)
      echo '1';
  else
      echo '0';
  ?&gt;
  </code></pre>
  
  <p>I also have an invalidHandler, but that thing is working so i guess it's useless to put it here.</p>
  
  <p>But I am stuck for hours now and I hope someone could help me with this problem.</p>