如何让我的联系表单正确调用PHP文件?

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:

echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com

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 http://www.mywebsite.com/test.php in a browser. It always works regardless of the send to address.

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.

Here is the contact form html code:

<form method="post" name="contact" action="mail.php"> 
      <input type="hidden" name="post" value="Send" /> 
      <label for="name">Name:</label> <input type="text" id="name" name="name"     class="required input_field" />
      <label for="email">Email Address:</label> <input type="text" id="email" name="email" class="validate-email required input_field" />
      <label for="url">Phone:</label> <input type="text" name="url" id="url" class="input_field" />
      <label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
      <input style="font-weight: bold;" type="submit" class="submit_btn" name="submit" id="submit" value="Send" />
      <input style="font-weight: bold;" type="reset" class="submit_btn" name="reset" id="reset" value="Reset" />
    </form>

Obviously this code is set within a page and has matching CSS.

And here is the PHP file "mail.php":

    <?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.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        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.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$name)) {
    $error_message .= 'The name you entered does not appear to be valid.<br />';
  }

    if(strlen($text) < 2) {
    $error_message .= 'The message you entered does not appear to be valid.<br />';
  }
    if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.

";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($name)."
";  
    $email_message .= "Email: ".clean_string($email_from)."
";
    $email_message .= "Phone: ".clean_string($url)."
";
    $email_message .= "Message: ".clean_string($text)."
";


    // email headers
    $headers = 'Reply-To: '.$email_from."
" .
    'X-Mailer: PHP/' . phpversion();
    mail($email_to, $email_subject, $email_message, $headers);
    ?>

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 http://www.mywebsite.com/mail.php It may be down for maintenance or configured incorrectly.

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.

Any help would be greatly appreciated. I've been working on this constantly for 4 days now.

Firstly, I want to ask you you to clean up your code. Part of your confusion is probably due to the your coding style. For starters, separate the functions and processing code.

Secondly, your posted code has a slight error, in that the statement if(isset($_POST['email'])) { does not have a matching close brace. That would be sufficient to generate an error.

if(isset($_POST['email'])) {
}

If the errors are not showing up, then it could be because of your PHP settings, try setting the error reporting level at the top of the file. Look here for a reference : http://php.net/manual/en/function.error-reporting.php

Then, lastly, the reason why there is no output is that you are not displaying anything when the mail() function finishes. So even if your script was working, you are asking it to end silently.

Fix those and report back.