$found_err = 0 ;
// Begin Error Code Here
if ($_POST['form_check']){
$errmsg = "Please enter your name. \n" ;
if (empty($_POST['name'])) {
$message = $message.$errmsg ;
$found_err = 1 ; }
$errmsg = "Please enter a valid phone number including area code. \n" ;
if (strlen(preg_replace("/\D/","",$_POST['phone'])) != 10) {
$message = $message.$errmsg ;
$found_err = 1 ;}
$errmsg = "Please enter a valid e-mail address. \n" ;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
$message = $message.$errmsg ;
$found_err = 1 ; }
$errmsg = "Please select a method of contact. \n" ;
if ($_POST['contactby'] == "How Should We Contact You?") {
$message = $message.$errmsg ;
$found_err = 1 ; }
$errmsg = "Please indicate whether you are a landlord or tenant. \n" ;
if ($_POST['type'] == "Are You A Landlord or Tenant?") {
$message = $message.$errmsg ;
$found_err = 1 ; }
}
if ($_POST['form_check'] && !$found_err){
// Format the dates I need to use
$my_time = time()-(60*60*15);
$current_time = date("F j, Y g:i A", $my_time);
$date_sent = date("D, d M y G:i:s T", $my_time);
$db_date = date("Y-m-d H:i:s", $my_time);
// Format phone number for email
$email_phone = preg_replace("/\D/","",$_POST['phone']);
$email_phone = "(".substr($email_phone,0,3).") ".substr($email_phone,3,3)."-".substr($email_phone,6,4);
// Format Comments for Email
$email_comments = preg_replace("[\r\n]"," ", $_POST['comments']);
// Prepare data before appending to database
$append_name = addslashes($_POST['name']);
$append_address = addslashes($_POST['address']);
$append_phone = preg_replace("/\D/","",$_POST['phone']);
$append_email = addslashes($_POST['email']);
$append_comments = addslashes($_POST['comments']);
$append_contactby = addslashes($_POST['contactby']);
$append_type = addslashes($_POST['type']);
// Append the data to the database
$connection = db_connect();
$sql = "INSERT INTO contacts (name, address, phone, email, comments, contact_method, contact_type, date) VALUES ('$append_name', '$append_address', '$append_phone', '$append_email', '$append_comments', '$append_contactby', '$append_type', '$db_date')";
$result = @mysql_query($sql,$connection)or die(mysql_error());
// Now send an email to the office
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "X-Mailer: php\n";
$headers .= "Date: $date_sent\n";
$headers .= "From: Information Request <$do_not_reply_email>\n";
$headers .= "Reply-To: Information Request <$do_not_reply_email>\n";
$email_subject = "$new_request_received_subject";
$email_message = "Your website received a form submission. Below are the results. \n" ;
$email_message .= "
| Name: |
|
".$_POST['name']." |
| Address: |
|
".$_POST['address']." |
| Phone #: |
|
$email_phone |
| Email: |
|
".$_POST['email']." |
| Comments: |
|
$email_comments |
| Contact By: |
|
".$_POST['contactby']." |
| Customer Type: |
|
".$_POST['type']." |
\n" ;
// Add the next line at a later date
// $email_message .= "To view all results, go to: ";
$email_message .=" This message was auto-generated on $current_time. Please do not reply. Your email will not be received.
\n";
mail ($default_email, $email_subject, $email_message, $headers);
echo "Thank you for contacting the Law Offices of Liddle & Liddle. We will respond as quickly as possible to your request.";
session_destroy();
exit;
}
else {
echo "
Request for Information...
Fill out the form and click submit. We will respond as quickly as possible to your request.
";
}
?>
|