title: How to validate form & send email with PHP
body: <p>I've done a tiny bit, but it is not so good. I would like to check if email is valid in proper format, name containing no numbers &amp; also how do I add validation to check if the Math question is right. Can anyone please help?</p>
  
  <pre><code>&lt;?php
      $submitted = $_POST["submitted"];
      if($submitted == "true")
      {
      $name = trim($_POST["name"]);
      $email = trim($_POST["email"]);
      $subject = trim($_POST["subject"]);
      $message = trim($_POST["message"]);
      $answerbox = trim($_POST["answerbox"]);
      if($name == "") print "&lt;p&gt;Please type your name.&lt;/p&gt;";
      if($subject == "") print "&lt;p&gt;Please type a subject.&lt;/p&gt;";
      if($email == "") print  "&lt;p&gt;Please type a valid email address.&lt;/p&gt;";
      if($message == "") print "&lt;p&gt;Please type your message.&lt;/p&gt;";
      if($answerbox == "") print "&lt;p&gt;Please answer the math question.&lt;/p&gt;";
      }
  
  ?&gt;
          &lt;form name="contact" action="form2.php" method="post"&gt;
              &lt;input type="hidden" name="submitted" value="true"/&gt;
              &lt;label for="YourName"&gt;Your Name:&lt;/label&gt;
              &lt;input type="text" name="name" class="required" /&gt;
  
              &lt;label for="YourEmail"&gt;Your Email:&lt;/label&gt;
              &lt;input type="text" name="email" class="required"/&gt;
  
              &lt;label for="Subject"&gt;Subject:&lt;/label&gt;
              &lt;input type="text" name="subject" class="required"  /&gt;
  
              &lt;label for="YourMessage"&gt;Your Message:&lt;/label&gt;
              &lt;textarea  name="message" class="required"&gt;&lt;/textarea&gt;
              &lt;p class="c3"&gt;10 + 5 =&lt;input type="text" name="answerbox" id="answerbox" /&gt;&lt;/p&gt;
  
          &lt;fieldset&gt;
              &lt;input type="submit" name="submit" id="submit" value="Send" class="required"/&gt;
              &lt;input type="reset" id="reset" value="Reset"/&gt;      
          &lt;/fieldset&gt;
  
      &lt;/form&gt;
  </code></pre>