title: How to add file attachment to existing contact form?
body: <p>I've been trying to customize a contact form that came with HTML site template to add file attachment / upload but with no success. Reason for trying to do this instead of embedding different contact form is simply because it's responsive and consistent with the rest of the site template. Any help would be great.</p>
  
  <p>This is the HTML part of the contact form:</p>
  
  
  
  <pre><code>    &lt;div class="row"&gt;
      &lt;div class="span9"&gt;
  
          &lt;form id="contact-form" class="contact-form" action="#"&gt;
              &lt;p class="contact-name"&gt;
                  &lt;input id="contact_name" type="text" placeholder="Full Name" value="" name="name" /&gt;
              &lt;/p&gt;
              &lt;p class="contact-email"&gt;
                  &lt;input id="contact_email" type="text" placeholder="Email Address" value="" name="email" /&gt;
              &lt;/p&gt;
              &lt;p class="contact-message"&gt;
                  &lt;textarea id="contact_message" placeholder="Your Message" name="message" rows="15" cols="40"&gt;&lt;/textarea&gt;
              &lt;/p&gt;
              &lt;p class="contact-submit"&gt;
                  &lt;a id="contact-submit" class="submit" href="#"&gt;Send Your Email&lt;/a&gt;
              &lt;/p&gt;
  
              &lt;div id="response"&gt;
  
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>and here's the PHP part:</p>
  
  <pre><code>&lt;?php
  
  header('Cache-Control: no-cache, must-revalidate');
  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  header('Content-type: application/json');
  
  $admin_email = 'your@yourdomain.com'; // Your Email
  $message_min_length = 5; // Min Message Length
  
  
  class Contact_Form{
  function __construct($details, $email_admin, $message_min_length){
  
      $this-&gt;name = stripslashes($details['name']);
      $this-&gt;email = trim($details['email']);
      $this-&gt;subject = 'Contact from Your Website'; // Subject 
      $this-&gt;message = stripslashes($details['message']);
  
      $this-&gt;email_admin = $email_admin;
      $this-&gt;message_min_length = $message_min_length;
  
      $this-&gt;response_status = 1;
      $this-&gt;response_html = '';
  }
  
  
  private function validateEmail(){
      $regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';
  
      if($this-&gt;email == '') { 
          return false;
      } else {
          $string = preg_replace($regex, '', $this-&gt;email);
      }
  
      return empty($string) ? true : false;
  }
  
  
  private function validateFields(){
      // Check name
      if(!$this-&gt;name)
      {
          $this-&gt;response_html .= '&lt;p&gt;Please enter your name&lt;/p&gt;';
          $this-&gt;response_status = 0;
      }
  
      // Check email
      if(!$this-&gt;email)
      {
          $this-&gt;response_html .= '&lt;p&gt;Please enter an e-mail address&lt;/p&gt;';
          $this-&gt;response_status = 0;
      }
  
      // Check valid email
      if($this-&gt;email &amp;&amp; !$this-&gt;validateEmail())
      {
          $this-&gt;response_html .= '&lt;p&gt;Please enter a valid e-mail address&lt;/p&gt;';
          $this-&gt;response_status = 0;
      }
  
      // Check message length
      if(!$this-&gt;message || strlen($this-&gt;message) &lt; $this-&gt;message_min_length)
      {
          $this-&gt;response_html .= '&lt;p&gt;Please enter your message. It should have at least '.$this-&gt;message_min_length.' characters&lt;/p&gt;';
          $this-&gt;response_status = 0;
      }
  }
  
  
  private function sendEmail(){
      $mail = mail($this-&gt;email_admin, $this-&gt;subject, $this-&gt;message,
           "From: ".$this-&gt;name." &lt;".$this-&gt;email."&gt;\r\n"
          ."Reply-To: ".$this-&gt;email."\r\n"
      ."X-Mailer: PHP/" . phpversion());
  
      if($mail)
      {
          $this-&gt;response_status = 1;
          $this-&gt;response_html = '&lt;p&gt;Thank You!&lt;/p&gt;';
      }
  }
  
  
  function sendRequest(){
      $this-&gt;validateFields();
      if($this-&gt;response_status)
      {
          $this-&gt;sendEmail();
      }
  
      $response = array();
      $response['status'] = $this-&gt;response_status;   
      $response['html'] = $this-&gt;response_html;
  
      echo json_encode($response);
  }
   }
  
  
   $contact_form = new Contact_Form($_POST, $admin_email, $message_min_length);
   $contact_form-&gt;sendRequest();
  
   ?&gt;
  </code></pre>
  
  <p>I've tried many different forms but with all I have to heavily change form's CSS/HTML formatting which results in site template breaking along the way.</p>