<?php
include ("db_functions.inc.php");
include ("config.inc.php");
if($_SERVER["REQUEST_METHOD"] == "POST") {
	$username=yasDB_clean($_POST['name']);
	$email=yasDB_clean($_POST['email']);
	$message=yasDB_clean($_POST['message'], true);
	if(strlen($name)>0 && strlen($email)>0 && strlen($message)>0)
	{
		$time=time();
		yasDB_insert("INSERT INTO contact (name,email,message,created_date) VALUES('$name','$email','$message','$time')");
		echo "<h2>Thank You !</h1>";
		$headers = 'From: '.$username.' <'.$username.'>';
		$subject = 'Contact message from '.$username.' through '.$setting['sitename'];
		$message .= "\n".'Return email: '.$email;
		if (@mail($setting['email'], $subject, $message, $headers)) {
			echo '<span style="color:red;">Message sent</span><br/><br/>';
		} else {
			echo '<span style="color:red;">Error sending message</span><br/><br/>';
		}
	}
	else {
		echo "<h2>An error occurred!</h2>";
	}
}
?>