title: error 500 on php form submission
body: <p>I'm trying to add a simple contact form with a recaptcha to my website, and have not been very successful. I keep receiving an error 500 whenever I try to test my form. The form points to separate php file located on my server.</p>
  
  <p>I'm really new to php, and I'm struggling to find out what's wrong. Here's the html for the form:</p>
  
  <pre><code>&lt;form method="post" action="form.php" id="contact-form" class="col s12"&gt;   
      &lt;div class="row"&gt;
          &lt;div class="input-field col m6 s12"&gt;
              &lt;input id="first_name" type="text" class="validate"&gt;
              &lt;label for="first_name"&gt;First Name&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="input-field col m6 s12"&gt;
              &lt;input id="last_name" type="text" class="validate"&gt;
              &lt;label for="last_name"&gt;Last Name&lt;/label&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="input-field col s12"&gt;
              &lt;input id="email" type="email" class="validate"required&gt;
              &lt;label for="email"&gt;Email&lt;/label&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="input-field col s12"&gt;
              &lt;textarea id="msg" class="materialize-textarea"&gt;&lt;/textarea&gt;
              &lt;label for="msg"&gt;Message&lt;/label&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="col s12 m6"&gt;
              &lt;div class="g-recaptcha" data-sitekey="xxxx-Xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx" data-type="image"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col s12 m6"&gt;
              &lt;button class="btn btn-large waves-effect waves-light" type="submit" name="action"&gt;Send Message&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here's <code>form.php</code>:</p>
  
  <pre><code>&lt;?php
  $secret='xxx-Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  $sitekey='xxx-Xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx';
  $first_name=$last_name=$email=$msg="";
  
  $email = test_input($_POST["email"]);
  if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $emailErr = "Invalid email format"; 
  }
  $msg = test_input($_POST["msg"]);
  
  if (isset($_POST['first_name'])) {
      $first_name=$_POST['first_name'];
      if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
            $nameErr = "Only letters and white space allowed"; 
      }
  }
  if (isset($_POST['last_name'])) {
      $last_name=$_POST['last_name'];
      if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
            $nameErr = "Only letters and white space allowed"; 
      }
  }
  $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&amp;response=".$captcha);
  if ($response.success==false) {
      echo '&lt;p&gt;Captcha failed.&lt;p&gt;'
      exit;
  }
  
  $toEmail='contact@example.org';
  
  $message = '&lt;p&gt;&lt;b&gt;First Name: &lt;/b&gt;'.$first_name.'&lt;/p&gt;'.
  '&lt;p&gt;&lt;b&gt;Last Name: &lt;/b&gt;'.$last_name.'&lt;/p&gt;'.
  '&lt;p&gt;&lt;b&gt;Email: &lt;/b&gt;'.$email.'&lt;/p&gt;'.
  '&lt;p&gt;&lt;b&gt;Message: &lt;/b&gt;&lt;br/&gt;'.$msg.'&lt;/p&gt;';
  $headers = 'From: first last &lt;contact@example.org&gt; '."rn".
  'Reply-To: '.$first_name.$last_name.' &lt;'.$email.'&gt; '. "rn".
  'Content-type: text/html'. "rn".
  'X-Mailer: PHP/'.phpversion();
  
  $message2 = '&lt;p&gt;&lt;b&gt;Here is a copy of your message: &lt;/b&gt;&lt;br/&gt;&lt;br/&gt;'.$first_name.' '.$last_name.'wrote: &lt;br/&gt;&lt;br/&gt;&lt;/p&gt;'.'&lt;p&gt;'.$msg'&lt;/p&gt;' 
  $headers2 = 'From:'.$toEmail."rn".'Reply-To: '.$toEmail."rn".
  'Content-type: text/html'. "rn".
  'X-Mailer: PHP/'.phpversion();
  
  mail($toEmail,'New Inquery from Website',$message,$headers);
  mail($email,'Copy of your form submission',$message2,$headers2);
  
  
  function test_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
  ?&gt;
  </code></pre>
  
  <p>Is there something wrong with my php/html? Or is it something else? My webserver uses php5-fpm and nginx on Ubuntu 14.04. Thanks for your help!</p>