I tried just the contact.php locally and it worked fine for me, in that it tried to do the redirect and I got a 404 not found since I don't have the 'thanks' page. However, my IDE was happier when I used single quotes instead of double quotes around the regexes in your preg_match() calls.
My test version:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
/* Set e-mail recipient */
$myemail = "nobodyhome@example.com";
// some fake test data:
$_POST = array(
'yourname' => 'your name',
'subject' => 'subject',
'email' => 'you@example.com',
'phone' => '111-222-33333',
'comments' => 'The comment'
);
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject = check_input($_POST['subject'], "Write a subject");
$email = check_input($_POST['email'], "Enter your email");
$phone = check_input($_POST['phone'], "Enter your phone");
$comments = check_input($_POST['comments'], "Write your comments");
/* If e-mail is not valid show error message */
if (!preg_match('([\w\-]+\@[\w\-]+\.[\w\-]+)/', $email)) {
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match('/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i', $website)) {
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
Name: $yourname
E-mail: $email
Subject:$subject
Phone: $phone
Comments:
$comments
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header("Location: thanks.html");
exit();
/* Functions we used */
function check_input($data, $problem = '')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0) {
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br/>
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>