<?php
//session_start();
/* This controller renders  the home page */

class regController{
	public function handleRequest(){
            global $defaultHomeLink;
            if ($_POST['pass2']=='meter5') {
            //global $auth,$login,$comnum,$user;
                $errors = '';
                $myemail = 'alee@wtrflw.com';//<-----Put Your email address here.
                if(empty($_POST['fname'])  ||
                    empty($_POST['lname'])  ||
                    empty($_POST['email']) ||
                    empty($_POST['uname'])  ||
                    empty($_POST['cname']))
                {
                    $errors .= "\n Error: all fields are required";
                }
                $fname = $_POST['fname'];
                $lname = $_POST['lname'];
                $uname = $_POST['uname'];
                $cname = $_POST['cname'];
                $email_address = $_POST['email'];
                if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",$email_address))
                {
                    $errors .= "\n Error: Invalid email address";
                }
                if( empty($errors))
                    {
                    $to = $myemail;
                    $email_subject = "Registration form submission: $fname";
                    $email_body = "You have received a new message. ".
                    " Here are the details:\n First Name: $fname \n Last Name: $lname \n Username: $uname \n".
                    "Company Name: $cname\n Email: $email_address\n";
                    $headers = "From: $myemail\n";
                    $headers .= "Reply-To: $email_address";
                    mail($to,$email_subject,$email_body,$headers);
                    //redirect to the 'thank you' page
                    echo '<script type=text/javascript>alert("Thank you for registering.  You will contacted soon");</script>';
                    echo '<meta http-equiv="refresh" content="2">';
                    //echo '<script type=text/javascript>window.location.href( '.$defaultHomeLink.'index.php );</script>';
                }
                } else {
                echo '<script type=text/javascript>alert("You did not pass the robot test!");</script>';  
                }
}
}
?>
