// method validates an email address
function isValidEmail($email) {
$reg1 = "/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/";
$reg2 = "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/";
if(!preg_match($reg1, $email) && preg_match($reg2, $email)) {
return true;
}
}
// method validates a date string
function isValidDate($date) {
$reg1 = "/\d{4}-\d{2}-\d{2}/";
if(preg_match($reg1, $date)) {
return true;
}
}
// method validates phone number (format xxx-xxx-xxxx)
function isValidPhone($phone) {
$reg1 = "/^(\s)*\d{3}-\d{3}-\d{4}(\s)*$/";
if(preg_match($reg1, $phone)) {
return true;
}
}
// method validates price format
function isValidPrice($price) {
$reg1 = "/^(\s)*\d{1,}\.\d{2}(\s)*$/";
if(preg_match($reg1, $price)) {
return true;
}
}
// method checks if string contains only digits
function isDigits($str) {
$reg1 = "/^[0-9]+$/";
if(preg_match($reg1, $str)) {
return true;
}
}
$error_msg = null;
$sent = false;
$process = $_POST['process'];
if($process == 1) {
$subject = trim($_POST['subject']);
$name = trim(ucwords($_POST['name']));
$email = trim($_POST['email']);
$comments = trim($_POST['comments']);
$phone = trim($_POST['phone']);
/*
if(empty($subject)) {
$error_msg .= "Please select a subject.
";
}
*/
if(empty($name)) {
$error_msg .= "Please enter your name.
";
}
if(!isValidEmail($email)) {
$email = null;
$error_msg .= "Please enter a valid email address.
";
}
if(empty($phone)) {
$error_msg .= "Please enter your phone number.
";
}
if($error_msg == null) {
$cc = null;
$bcc = null;
$to = "cbaptiste@phylsacademy.com";
$from = "website@phylsacademy.com";
$subject = "Website Inquiry";
$msg_body .= "The following email was sent from the Phyls Academy website.
";
// $msg_body .= "Contact me about ".$frSubject."
";
$msg_body .= ($name)? "Name: ".$name."
" : "";
$msg_body .= "
";
$msg_body .= ($phone)? "Phone: ".$phone."
" : "";
$msg_body .= ($fax)? "Fax: ".$fax."
" : "";
$msg_body .= ($email)? "Email: $email
" : "";
$msg_body .= "
";
/*
if(!empty($frAddress) || !empty($frState) || !empty($frCity) || !empty($frZipcode)) {
$msg_body .= "Mailing Address:
"; $msg_body .= ($frAddress)? "Address: $frAddress"; } */ $msg_body .= "Comments
" : "No street address provided.
"; $msg_body .= ($frState)? "State: $frState
" : ""; $msg_body .= ($frCity)? "City: $frCity
" : ""; $msg_body .= ($frZipcode)? "Zipcode: $frZipcode
" : ""; $msg_body .= "
$comments" : "No comments submitted"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $from \r\n"; if($cc != NULL) $headers .= "Cc: $cc \r\n"; if($bcc != NULL) $headers .= "Bcc: $bcc \r\n"; $sent = mail($to, $subject, $msg_body, $headers); if(!$sent) { $error_msg .= "Your mail could not be sent. Please try again. "; } } } ?>