I know a number of people have tried to answer this question but I have to ask because I have tried all the proposed solutions and none of them work for me. Whenever I attempt to test the PHP code it displays the error 'Cannot POST /contact.php'.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="HandheldFriendly" content="true">
</head>
<body>
<form action="contact.php" method="post">
<div class="container-fluid contact-form">
<div class="row centered content">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b1">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
<input class="contact-info name" type="text" placeholder="Name" name="yourname" />
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
<input class="contact-info email" type="text" placeholder="Email" name="email" />
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
<input class="contact-info number" type="text" placeholder="Contact number" name="comments" />
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
<input class="contact-info subject" type="text" placeholder="Subject" name="subject" />
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b2">
<textarea class="contact-message" name="comments" placeholder="Message" rows="10" cols="40"></textarea>
<p class="how">How did you find out about 9haus?
<select name="how">
<option class="select" value=""> -- Please select -- </option>
<option>Google search</option>
<option>From a friend</option>
<option>Link from a website</option>
<option>9haus Publications</option>
<option>Other</option>
</select>
</p>
</div>
</div>
<div class="container-fluid contact-f">
<div class="row centered">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b">
<p><input class="send" type="submit" name="submit" value="Send"></p>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
And now the PHP code
<?php
/* Set e-mail recipient */
$myemail = "review@studios.com";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
$subject = check_input($_POST['subject'], "Write a subject");
$how_find = check_input($_POST['how']);
$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("Please enter valid email address");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
if(isset($_POST['submit'] && $human == '15')
else if(isset($_POST['submit'] && $human != '15')
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your request has been submitted to the 9haus graphics team:
Name: $yourname
E-mail: $email
URL: $website
How did he/she find it? $how_find
Comments:
$comments
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* 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();
}
?>
Any thoughts as to what I might be doing wrong?