
<?php

function removeHTML($texttovalid){
		$texttovalid = trim($texttovalid);
		if(strlen($texttovalid)>0){
			$texttovalid = htmlspecialchars(stripslashes($texttovalid));
		}
		return $texttovalid;
}

if(isset($_POST['submit'])){

	$name = removeHTML($_POST['name']);
	$email = removeHTML($_POST['email']);
	$subject = removeHTML($_POST['subject']);
	$message = removeHTML($_POST['message']);
	$msg ='';
	
	if($name==''){
		$msg = '<li>Name is a required field.</li>';
	}
	if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){
	   $msg .= '<li>Invalid Email Address</li>';
	}
	if($subject==''){
		$msg .= '<li>Subject is a required field.</li>';
	}
	if($message==''){
		$msg .= '<li>Message is a required field.</li>';
	}
	
	if($msg!=''){
		$msg = '<div class="errorMsg"><h3>Message Field!</h3><ul>' . $msg . '</ul></div>';
	}
	else{
		
		/*Change this email to your email address*/
		$to = "joefrey.mahusay@gmail.com";
		
		
		$headers = "From: $email";
		$subject = $subject." - A message from The Freelancer";
		$body = "Name: $name\n\n"
			. "Email: $email\n\n"
			. "Subject: $subject\n\n"
			. "Message: $message"
			;
		$ok = (mail($to, $subject, $body, $headers));
		
		if($ok){
		$msg = '<div class="infoMsg"><h3>Message Sent!</h3><p>Thank you for contacting us. We will get back to you shortly!</p></div>';
		}else{
		$msg = '<div class="errorMsg"><h3>Message Failed!</h3><p>Please try again.</p></div>';
		}	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Freelancer - A premium grunge portfolio template for freelancers out there</title>
<!--This theme was created by Joefrey Mahusay for themeforest.net -->

<!--reset.css - reset the default value to 0 -->
<link href="css/reset.css" type="text/css" rel="stylesheet" />

<!--style.css - this is the style of the over all look and feel of the template.-->
<link href="css/style.css" type="text/css" rel="stylesheet" />

<!--Fixing IE6PNG -->
<script src="js/unitpngfix.js" type="text/javascript"></script>


</head>

<body>
	<!--BEGIN page-->
	<div id="page">
    	<!--BEGIN wrap-->
    	<div id="wrap">
        	<!--BEGIN header-->
	    	<div id="header">
            	
            	<!--BEGIN logo-->
            	<h1 id="logo"><a href="index.html">The Freelancer</a></h1>
                <!--END of logo-->
                
                <!--BEGIN availabilty--> 
                <div class="availability">
                   	<a href="#" class="available">I'm available for freelance work</a>
                </div>
                <!--END of availability-->
                
                 <!--BEGIN menu_wrap-->
                <div id="menu_wrap">

					<!--BEGIN menu-->
                    <ul id="menu">
                        <li><a href="index.html" title="Homepage">Home</a></li>
                        <li><a href="about.html" title="About Me">About</a></li>
                        <li><a href="work.html" title="My Work">Work</a></li>
                        <li><a href="services.html" title="My Services">Services</a></li>
                        <li><a href="contact.php" title="Get in Touch" class="current">Contact</a></li>
                    </ul>
                    <!--END of menu-->
                </div>
                <!--END of menu_wrap-->
                
             	<!--BEGIN feature_project-->
                <div id="title_page">
                	<h2>Get in touch</h2>
	            </div>   
                <!--END of feature_project-->
                
            </div>
           	<!--END of header-->

            <!--BEGIN main_conten-->
            <div id="main_content">
                <!--BEGIN content-->
            	<div id="content">
                <h2>Contact Form</h2>
                <p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.</p>
                
                
                  <?php echo $msg;?>
                  <form id="contact_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                    <p>
                      <label for="name">Name:</label><input type="text" name="name" id="name" value="<?php echo $name;?>" />
                    </p>
                    <p>
                      <label for="email">Email:</label><input type="text" name="email" id="email" value="<?php echo $email;?>"  />
                    </p>
                    <p>
                      <label for="subject">Subject:</label><input type="text" name="subject" id="subject" value="<?php echo $subject;?>"  />
                    </p>
                    <p>
                      <label for="message">Message:</label>
                      <textarea name="message" id="message" rows="5" cols="20"><?php echo $message;?></textarea>
                    </p>
                    <p>
                      <label>&nbsp;</label><input type="submit" value="Send a Message" name="submit" class="send_btn"/>
                    </p>
                  </form>
                </div>
                 <!--END of content-->
                
                
                 <!--BEGIN sidebar-->	
                <div id="sidebar">
                	<img src="images/map.gif" alt="Map" class="map" />
                     <div class="block">
                     <blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p>
                    <p><cite><strong>John Doe</strong>, President, <a href="#">XYZ Company</a></cite></p>
                    </blockquote>
                    </div>
                </div>
                 <!--END of sidebar-->
            
            <!--BEGIN push - makes our footer stick at the bottom of the page. -->
            <div class="push"></div>    
            <!--END of push -->
            
            </div>
            <!--END of main_conten-->
            
            
            <!--BEGIN of footer-->
            <div id="footer">
            	<div class="copyright">
	            	<small>&copy; 2009 More Templates <a href="http://www.cssmoban.com/" target="_blank" title="模板之家">模板之家</a> - Collect from <a href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a>. All rights reserved</small>
                </div>
            </div>
        	<!--END of wrap-->    
            
        </div>
        <!--END of wrap-->
    </div>
    <!--END of page-->
    
</body>
</html>
