title: How do I get my contact form to call the PHP file correctly?
body: <p>I'm hosting my website on my personal Ubuntu LAMP server. Everything is working but the contact form. I have Postfix configured to relay emails through my gmail smtp and it's working brilliantly. I know my server is sending emails. I've verified this with the following code several times to a variety of addresses:</p>
  
  <pre><code>echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com
  </code></pre>
  
  <p>I've also verified that PHP is working by creating a small PHP files "test.php" and saving it in my /var/www directory. I then call the file by entering <a href="http://www.mywebsite.com/test.php" rel="nofollow">http://www.mywebsite.com/test.php</a> in a browser. It always works regardless of the send to address.</p>
  
  <p>So, knowing the server sends emails, and that PHP is functioning, that leads me to the code or perhaps some issue related to the calling of the PHP file when the send button is clicked on the contact form.</p>
  
  <p>Here is the contact form html code:</p>
  
  <pre><code>&lt;form method="post" name="contact" action="mail.php"&gt; 
        &lt;input type="hidden" name="post" value="Send" /&gt; 
        &lt;label for="name"&gt;Name:&lt;/label&gt; &lt;input type="text" id="name" name="name"     class="required input_field" /&gt;
        &lt;label for="email"&gt;Email Address:&lt;/label&gt; &lt;input type="text" id="email" name="email" class="validate-email required input_field" /&gt;
        &lt;label for="url"&gt;Phone:&lt;/label&gt; &lt;input type="text" name="url" id="url" class="input_field" /&gt;
        &lt;label for="text"&gt;Message:&lt;/label&gt; &lt;textarea id="text" name="text" rows="0" cols="0" class="required"&gt;&lt;/textarea&gt;
        &lt;input style="font-weight: bold;" type="submit" class="submit_btn" name="submit" id="submit" value="Send" /&gt;
        &lt;input style="font-weight: bold;" type="reset" class="submit_btn" name="reset" id="reset" value="Reset" /&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Obviously this code is set within a page and has matching CSS.</p>
  
  <p>And here is the PHP file "mail.php":</p>
  
  <pre><code>    &lt;?php
  if(isset($_POST['email'])) {
  
      // CHANGE THE TWO LINES BELOW
      $email_to = "tljefam@gmail.com";
      $email_subject = "OYH Tech Website Email";
  
  
      function died($error) {
          // error code
          echo "We are very sorry, but there were error(s) found with the form you submitted. ";
          echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;";
          echo $error."&lt;br /&gt;&lt;br /&gt;";
          echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
          die();
      }
  
      // validation expected data exists
          if(!isset($_POST['author']) ||     
          !isset($_POST['email']) ||
          !isset($_POST['url']) ||
          !isset($_POST['text'])) {
          died('We are sorry, but there appears to be a problem with the form you submitted.');      
      }
  
      $name = $_POST['author']; // required  
      $email_from = $_POST['email']; // required
      $url = $_POST['url']; // not required
      $text = $_POST['text']; // required
  
      $error_message = "";
      $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
      $error_message .= 'The Email Address you entered does not appear to be valid.&lt;br /&gt;';
    }
      $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$name)) {
      $error_message .= 'The name you entered does not appear to be valid.&lt;br /&gt;';
    }
  
      if(strlen($text) &lt; 2) {
      $error_message .= 'The message you entered does not appear to be valid.&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 .= "Name: ".clean_string($name)."\n";  
      $email_message .= "Email: ".clean_string($email_from)."\n";
      $email_message .= "Phone: ".clean_string($url)."\n";
      $email_message .= "Message: ".clean_string($text)."\n";
  
  
      // email headers
      $headers = 'Reply-To: '.$email_from."\r\n" .
      'X-Mailer: PHP/' . phpversion();
      mail($email_to, $email_subject, $email_message, $headers);
      ?&gt;
  </code></pre>
  
  <p>When I click send on the contact form it loads a blank page, and that's it. No error code, or message of any kind, and more importantly no email delivered. Some browsers give the following message: The website encountered an error while retrieving <a href="http://www.mywebsite.com/mail.php" rel="nofollow">http://www.mywebsite.com/mail.php</a> It may be down for maintenance or configured incorrectly.</p>
  
  <p>To be clear, I merely want this contact form to send emails to my gmail address and nothing more. I do not receive emails on this server.</p>
  
  <p>Any help would be greatly appreciated. I've been working on this constantly for 4 days now.</p>