<?php
session_start();

$_SESSION["postInvestor"] = $_POST;

$name = $_POST["name"];
$email = $_POST["email"];
$contact = $_POST["contact"];
$txtMessage = $_POST["txtMessage"];
$vcode = $_POST["vcode"];

if(empty($name) || empty($email) || empty($txtMessage) || empty($contact)) {
	echo "<script> location.href='invmsg.php?error=Please fill in all fields.'</script>";
	die;
}
if (md5($vcode) != $_SESSION['image_random_value']) {
	echo "<script> location.href='invmsg.php?error=Invalid Verification Code.'</script>";
	die;
}
if(!preg_match( "/^[-a-zA-Z0-9_\\.]+\\@([0-9A-Za-z][0-9A-Za-z-]+\\.)+[A-Za-z]{2,5}+$/", $email)) {
	echo "<script> location.href='invmsg.php?error=Invalid Email!'</script>";
	die;
}
if(!preg_match("/^[0-9]+$/", $contact)) {
	echo "<script> location.href='invmsg.php?error=Limit to Number only!'</script>";
	die;
}

$content = "-------------------------------Investor Message by $name-------------------------------\n";

$content .= "Name: $name\n";
$content .= "Email: $email\n";
$content .= "Contact: $contact\n";
$content .= "Message: $txtMessage";

mail("jadiatang@gmail.com", "Investor Message by $name", "$content", "From: $email");
$_SESSION["postInvestor"]="";
	echo "<script> location.href='invmsg.php?error=Succeed sent! We will get back to you soon!'</script>";
?>