Why PHP form causing 500 Internal Server Error All of a sudden
<p>My registration form is causing a 500 internal server error. The page is timing out before the script executes (from server people)."Script timed out before returning headers: index.php, " I'm not a php developer but use it and customize it, so i have no idea what would cause this. Is it something in the form and thanks page? Hoping someone here might have some ideas. I turned on php error reporting and no errors are displayed. The error mentions "headers" so wondering if it the line: header("Location: $thanksPage"); - thanks for your help...</p>

<pre><code>// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!
error_reporting(E_ALL);
ini_set('display_errors', '1');

$yourEmail = "my@email.com"; // the email address you wish to     receive these mails through
$yourWebsite = "Maine Firearm Instruction"; // the name of your website
$thanksPage = 'thanks.php'; // URL to 'thanks for sending mail' page; leave empty to     keep message on the same page 
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4


// DO NOT EDIT BELOW HERE

$error_msg = null;
$result = null;

function isBot() {
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-  Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot");

$isBot = false;
foreach ($bots as $bot)
if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
    $isBot = true;

if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
    $isBot = true;

exit("Bots not allowed.&lt;/p&gt;");
}

if ($_SERVER['REQUEST_METHOD'] == "POST") {
function clean($data) {
    $data = trim(stripslashes(strip_tags($data)));
    return $data;
}

// lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score.. 
// score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
$points = (int)0;

$badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur");
$exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");

foreach ($badwords as $word)
    if (strpos($_POST['comments'], $word) !== false)
        $points += 2;

foreach ($exploits as $exploit)
    if (strpos($_POST['comments'], $exploit) !== false)
        $points += 2;

if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
    $points += 2;
if (isset($_POST['nojs']))
    $points += 1;
if (preg_match("/(&lt;.*&gt;)/i", $_POST['comments']))
    $points += 2;
if (strlen($_POST['name']) &lt; 3)
    $points += 1;
if (strlen($_POST['comments']) &lt; 15 || strlen($_POST['comments'] &gt; 1500))
    $points += 2;
// end score assignments

foreach ($_POST as $key =&gt; $value)
    $_POST[$key] = trim($value);

if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['ename']) || empty($_POST['ephone']) || empty($_POST['age']) || empty($_POST['class']) || empty($_POST['pay'])) {
    $error_msg .= "Required fields are noted with an asterisk '*'. \n";

} elseif (strlen($_POST['name']) &gt; 20) {
    $error_msg .= "The name field is limited at 20 characters. \n";
} elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) {
    $error_msg .= "The name field must not contain special characters. \n";
} elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) {
    $error_msg .= "Invalid email address - please enter a valid e-mail address. \n";    
}
if ($error_msg == NULL &amp;&amp; $points &lt;= $maxPoints) {
    $subject = "MFAI online registration";
    $subject2 = "MFAI Online Registration";

    $message = "The following MFAI class registration was submitted from the MFAI website: \n\n";
    $message2 = "Thank you for registering for a MFAI class. We've received the following information: \n\n";
    foreach ($_POST as $key =&gt; $val) {
        $message .= ucwords($key) . ": " . clean($val) . "\r\n";
        $message2 .= ucwords($key) . ": " . clean($val) . "\r\n";
    }
    $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
    $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
    $message .= 'Points: '.$points;
    $message2 .= "Please let us know if you have any questions prior to class. We look forward to seeing you at class! \r\n Maine Firearm Instruction, LLC \r\n 207.754.8014 \r\n chris@mainefirearminstruction.com";


    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
        $headers   = "From: $yourEmail \r\n";
        $headers  .= "Reply-To: $yourEmail";
    } else {
        $headers   = "From: $yourWebsite &lt;$yourEmail&gt; \r\n";
        $headers  .= "Reply-To: $yourEmail";
    }

    if (mail($yourEmail,$subject,$message,$headers))   {

        if (!empty($thanksPage)) {              
            if(  (!empty( $_POST['pay']))  &amp;&amp; ($_POST['pay'] != "please select")  &amp;&amp; (!empty( $_POST['acfga-member'] )) )
            {
                //redirect here
                session_start();                    
                unset($_SESSION['name']);
                unset($_SESSION['phone']);
                unset($_SESSION['cphone']);
                unset($_SESSION['email']);
                unset($_SESSION['address']);
                unset($_SESSION['city']);
                unset($_SESSION['state']);
                unset($_SESSION['zip']);
                unset($_SESSION['age']);
                unset($_SESSION['ename']);
                unset($_SESSION['ephone']);
                unset($_SESSION['class']);
                unset($_SESSION['pay']);
                unset($_SESSION['comments']);
                unset($_SESSION['howfind']);
                unset($_SESSION['other']);
                unset($_SESSION['acfga-member']);

                $_SESSION['name'] = $_POST['name'];
                $_SESSION['phone'] = $_POST['phone'];
                $_SESSION['cphone'] = $_POST['cphone'];
                $_SESSION['email'] = $_POST['email'];
                $_SESSION['address'] = $_POST['address'];
                $_SESSION['city'] = $_POST['city'];
                $_SESSION['state'] = $_POST['state'] ;
                $_SESSION['zip'] = $_POST['zip'];
                $_SESSION['age'] = $_POST['age'];
                $_SESSION['ename'] = $_POST['ename'];
                $_SESSION['ephone'] = $_POST['ephone'];
                $_SESSION['class'] = $_POST['class'];
                $_SESSION['pay'] = $_POST['pay'];   
                $_SESSION['comments'] = $_POST['comments']; 
                $_SESSION['howfind'] = $_POST['howfind'];
                $_SESSION['other'] = $_POST['other'];   
                $_SESSION['acfga-member'] = $_POST['acfga-member']; 


                //print_r($_SESSION['plan']);
                //print_r($_SESSION['pay']);
                //header("Refresh: 0; url=".$thanksPage."");
                header("Location: $thanksPage");

                //exit;
            }
        } else {
            $result = 'Your registraiton was successfully sent.';
        }
    } else {
        $error_msg = 'Your registration could not be sent this time.';
    }
} else {
    if (empty($error_msg))
        $error_msg = 'Your message looks too much like spam, and could not be sent this time. ['.$points.']';
}
}
function get_data($var) {
if (isset($_POST[$var]))
    echo htmlspecialchars($_POST[$var]);
}
</code></pre>
