Message Sent:
To: $recipient
Subject: $subject
Message:
$msg");
else
echo "Message failed to send";
}
?>
/ initialize a variable to
// put any errors we encounter into an array
$errors = array();
// test to see if the form was actually
// posted from our form
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer\n";
// check to see if a name was entered
if (!$_POST['Name'])
// if not, add that error to our array
$errors[] = "Name is required";
// check to see if a subject was entered
if (!$_POST['Subject'])
// if not, add that error to our array
$errors[] = "Subject is required";
// check to see if a message was entered
if (!$_POST['MsgBody'])
// if not, add that error to our array
$errors[] = "Message body is required";
// if there are any errors, display them
if (count($errors)>0){
echo "ERROR:
\n";
foreach($errors as $err)
echo "$err
\n";
} else {
// no errors, so we build our message
$recipient = 'user@example.com';
$from = stripslashes($_POST['Name']);
$subject = stripslashes($_POST['Subject']);
$msg = "Message sent by $from\n
".stripslashes($_POST['MsgBody']);
if (mail($recipient,$subject,$msg))
echo "Thanks for your message!";
else
echo "An unknown error occurred.";
}