<?php
##################################################################################
# Script : writedocMail, version 1.4, March 2004 #
# Description : Basic PHP-based Form Processor with required field checking #
# Requirements : PHP installed on your hosting server & register_globals enabled #
# File : writedocMail.php #
# Copyright : © Malcolm Graham, 2003-2004 #
# Updates, see : http://writedoc.com/programs/writedocMail/ #
# For help, see: http://www.php.net/, http://www.hotscripts.com/, #
# http://www.devscripts.com/, or http://www.phpfreaks.com #
# #
# Instructions... #
# 1. Download and decompress the wriredocMail.zip file #
# 2. Change $mailTo text to your email address #
# Jump to Step 10, if you are using the sample form (feedback.htm) & files #
# 3. Create your Form with link to this file as the Form's POST Action #
# 4. Change $msgSubject text to what you want #
# 5. Change $formSuccess to location of your successful form submission page #
# 6. Change/Add $formError with location of your form processing error pages #
# 7. Add a variable for all fields in your form #
# 8. Add case statements for every user-input field in your form #
# 9. Add your form field names and associated $variable-name to msgBody #
# 10. Save this file in the script folder within the writedocMail folder #
# 11. Move writedocMail folder to your server & call your form from any page #
##################################################################################
$mailTo = "hide@address.com";
$msgSubject = "Site Feedback";
$formSuccess = "../responses/formSuccess.htm";
//Add a formError statement for each user-input field
$formError1 = "../responses/formError1.htm";
$formError2 = "../responses/formError2.htm";
$formError3 = "../responses/formError3.htm";
$formError4 = "../responses/formError4.htm";
//List of all form variables and field names
$realname = stripslashes($realname); //required
$email = stripslashes($email); //required
$address = stripslashes($address); //optional
$message = stripslashes($message); //required
//Add one statement for every form field
switch(true):
//Validate that all user-input form fields contain valid data
case (empty($realname) || !preg_match("/^[a-zA-Z ]+$/",$realname)):
header("Location: $formError1");
break;
Case (empty($email) || !preg_match("/^\s*[^@\r\n\t\#\$\%\;]+@[^@\r\n\t\#\$\%\;]+\.\w{2,3}\s*$/",$email)):
header("Location: $formError2");
break;
Case (!empty($address) && !preg_match("/^[a-zA-Z0-9 \,\.]+$/",$address)):
header("Location: $formError3");
break;
Case (empty($message) || !preg_match("/^[a-zA-Z0-9 \`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\{\]\}\\\|\;\:\'\"\,\<\.\>\/\?\t\r\n]+$/",$message)):
header("Location: $formError4");
break;
//Add a case statement for each additional user-input field
default:
//Valid data, formatted for output, add an entry for each form field
$msgBody = "Message from: $realname, Email: $email\nAddress: $address\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");
break;
endswitch;
?>