// 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']);
$friend_name = trim(ucwords($_POST['friend_name']));
$friend_email = trim($_POST['friend_email']);
$friend_phone = trim($_POST['friend_phone']);
$comments = trim($_POST['comments']);
/*
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($friend_name)) {
$error_msg .= "Please enter your friend's name.
";
}
if(!isValidEmail($friend_email)) {
$friend_email = null;
$error_msg .= "Please enter a valid email address for your friend.
";
}
/*
if(empty($friend_phone)) {
$error_msg .= "Please enter your friend's phone number.
";
}
*/
if($error_msg == null) {
// Send referral to friend
$cc = null;
$bcc = null;
$to = $friend_email;
$from = $email;
$subject = "Your friend ".$name." thought you would be interested in our Academy";
$msg_body .= "Hi ".$friend_name."
";
$msg_body .= "
Your friend ".$name." thought you would be interested in Phyls Academy and the services we have to offer. Recognized as one of the top Academies in South Florida, Phyls Academy helps shape the lives of hundreds of students and prepare them for the future.
"; if(!empty($comment)) { $msg_body .= $name." said ...".$comment."
"; } $msg_body .= "Learn more about Phyls Academy by visiting our website at http://www.phylsacademy.com
"; $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); // Send info to school $cc = null; $bcc = null; $to = "cbaptiste@phylsacademy.com"; $from = "website@phylsacademy.com"; $subject = "Phyls Website Referred to ".$friend_name; $msg_body .= "HiThe Phyls Academy website was recently referred by ".$name." (".$email.") to ".$friend_name." (".$friend_email.")
"; if(!empty($friend_phone)) { $msg_body .= "".$friend_name."'s phone number is ".$friend_phone."
"; } if(!empty($comment)) { $msg_body .= $name." said ...".$comment."
"; } $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. "; } } } ?>