Hey guys,
I have a bit of an issue here that I'm not sure what the cause of it may be. I have built a basic PHP contact form with basic conditionals and verifiers. The form seems to work, but not every time. I set my email for delivery to be Yahoo.com one and I seem to only get form submissions once every while, instead of every time form is submitted. I try different steps (like refreshing, not filling out fields to cause conditional error and then submitting, etc), but so far nothing conclusive.
Is this something with server settings I need to adjust? Is it Yahoo problem? Is it problem with my code? Please check it out and let me know what the solution might be to this.
Here is the code:
<?php
if(empty($_POST)) {
$status = '';
$display_form = true;
}
else {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$security = $_POST['security'];
$message = $_POST['message'];
$error_list = array();
if(empty($fname)) {
$error_list[] = 'First Name is required';
}
if(empty($lname)) {
$error_list[] = 'Last Name is required';
}
if(empty($email)) {
$error_list[] = 'Email Address is required';
}
if(empty($message)) {
$error_list[] = 'Message is required';
}
if ($security != "52190") {
$error_list[] = 'Security Number is incorrect';
}
if(empty($error_list)) {
$email_contents = "The following message was sent to you from your website:\n\n ";
$email_contents .= "fname: $fname\n ";
$email_contents .= "lname: $lname\n ";
$email_contents .= "email: $email\n\n ";
$email_contents .= "$subject \n\n ";
$email_contents .= $message;
$extra_headers = "From: $name <$email>\n\n ";
$extra_headers .= "User Email: $email ";
mail('example@yahoo.com' ,'Contact Form Submission From Openwave', $email_contents, $extra_headers);
$status = "<ul><li>Message Sent. Thanks, $fname! </li></ul>";
$display_form = false;
}
else{
$status = '<ul>';
foreach($error_list as $error_message) {
$status .= "<li>$error_message</li>";
}
$status .= '</ul>';
$display_form = true;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TRxhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="styles/main.css" />
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/new_window.js"></script>
<title>Blocked</title>
</head>
<body>
<div id="wrapper">
<div id="contact_holder_2">
<h4 class="title_style_2">Contact Form</h4>
<?php echo $status; ?>
<?php if($display_form) { ?>
<div id="form">
<form action="contact.php" method="post">
<dl>
<dt><label for="fname"> First Name: </label></dt>
<dd><input type="text" id="fname" name="fname" size="30" /></dd>
<dt><label for="lname"> Last Name: </label></dt>
<dd><input type="text" id="lname" name="lname" size="30" /></dd>
<dt><label for="email"> Email Address: </label></dt>
<dd><input type="text" id="email" name="email" size="30" /></dd>
<dt>Subject:</dt>
<dd><label>
<select name="subject" id="subject">
<option value="general_feedback">General Feedback</option>
<option value="work_feedback">Work Feedback</option>
<option value="website_feedback">Website Feedback</option>
<option value="freelance">Freelance Opportunity</option>
<option value="job">Job Opportunity</option>
</select>
</label>
</dd>
<dt><label for="message">Your Message:</label></dt>
<dd><textarea name="message" id="message" rows="10" cols="37"></textarea></dd>
</dl>
<div id="contact_btns">
<input type="submit" value="Send" />
<input type="reset" value="Clear Form" />
</div> <!-- form buttons -->
</form>
</div>
<?php } ?>
</div> <!-- contact Holder 2-->
<div id="empty_2"></div>
<div id="footer">
<a href="#top">[ Back To Top ]</a>
</div> <!-- footer -->
</div> <!-- Wrapper -->
</body>
</html>