title: Form to Email Contact Form
body: <p>Hi im having problems with my PHP code for sending an email via a contact form. The form used to work, but it stopped sending e-mails. I am new at php so please help.I am getting no errors and can see no problem with the code after researching it thoroughly, could someone help me??  Here is my code...</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['email'])) {
  
      // EDIT THE 2 LINES BELOW AS REQUIRED
      $email_to = "#@gmail.com";
      $email_subject = "##";
  
  
      function died($error) {
          // your error code can go here   
          echo "&lt;img src=\"../images/errors.found.png\"/&gt;";
          echo "&lt;br /&gt;&lt;img src=\"../images/errors.below.png\"/&gt;&lt;br /&gt;&lt;br /&gt;";
          echo $error."&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;               &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href='/home/form/contactform.htm'&gt;&lt;img src=\"../images/back.png\"/&gt;&lt;/a&gt;"; 
          die();
      }
  
      // validation expected data exists
      if(!isset($_POST['first_name']) ||
          !isset($_POST['last_name']) ||
          !isset($_POST['email']) ||
          !isset($_POST['telephone']) ||
          !isset($_POST['guests']) ||
          !isset($_POST['comments'])) {
          died('');       
      }
  
      $first_name = $_POST['first_name']; // required
      $last_name = $_POST['last_name']; // required
      $email_from = $_POST['email']; // required
      $telephone = $_POST['telephone']; //  required
      $guests = $_POST['guests']; //  required
      $comments = $_POST['comments']; // required
  
      $error_message = "";
  
      $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {
      $error_message .= '&lt;img src="../images/fname.valid.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }
    if(!preg_match($string_exp,$last_name)) {
      $error_message .= '&lt;img src="../images/lname.valid.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }
      $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
      $error_message .= '&lt;img src="../images/email.vaild.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }
      $string_exp = "/^[0-9 .'-]+$/";
    if(!preg_match($string_exp,$telephone)) {
      $error_message .= '&lt;img src="../images/phone.valid.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }  
      $string_exp = "/^[0-9 .'-]+$/";
    if(!preg_match($string_exp,$guests)) {
      $error_message .= '&lt;img src="../images/guests.valid.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }
    if(strlen($comments) &lt; 0) {
      $error_message .= '&lt;img src="../images/comments.valid.png" width="744" height="26" /&gt;&lt;br /&gt;';
    }
    if(strlen($error_message) &gt; 0) {
      died($error_message);
    }
      $email_message = "Form details below.\n\n";
  
      function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
      }
  
      $email_message .= "First Name: ".clean_string($first_name)."\n";
      $email_message .= "Last Name: ".clean_string($last_name)."\n";
      $email_message .= "Email: ".clean_string($email_from)."\n";
      $email_message .= "Telephone: ".clean_string($telephone)."\n";
      $email_message .= "Number of guests: ".clean_string($guests)."\n";
      $email_message .= "Comments: ".clean_string($comments)."\n";
  
  
  // create email headers
  $headers = 'From: '.$email_from."\r\n".
  'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  @mail($email_to, $email_subject, $email_message, $headers);  
  ?&gt;
  
  &lt;!-- include your own success html here --&gt;
  
  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="../images/email_sent.gif" width="685" height="51" /&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>