<?php 
// Form Variables and Field names
$realname = stripslashes($realname);
$email = stripslashes($email);
$subject = stripslashes($subject);
$message = stripslashes($message);

$mailTo = "david@rationalmind.net";
$msgSubject = "RationalMind Website Message from " . $realname;
$formName = "/david/contact?msg=contact";
$formError = "/david/contact?msg=error";
$formSuccess = "/david/contact?msg=success"; 
// Checking for data in required form fields
if (!isset($email) || !isset($message)) {
    header("Location: $formName");
} elseif (empty($email) || empty($message)) {
    header("Location: $formError");
} else {
    // Message body text and header text
    $msgBody = "Message from: $realname, Email: $email\nsubject: $subject\nMessage:\n$message";
    $xHeaders = "From: $realname ($email)"; 
    // PHP Mail Function call
    mail ($mailTo, $msgSubject, $msgBody, $xHeaders); 
    // Page to be displayed after successful form submission
    header ("Location: $formSuccess");
} 

?>
