Thank you!
Your request has been sent."; // form fields /* every form field is an array consisting of 6 elements: 1) field caption 2) field name 3) field type: line, field, radio 4) additional info: if field type is - 'radio' this field contains the radio captions/values like so: {caption1|value1} {caption2|value2} {caption3|value3}... - 'select' this field contains the radio captions/values like so: {caption1|value1} {caption2|value2} {caption3|value3}... - 'email' the field value must be a valid emailaddress 5) mandatory ('*') or not ('') 6) error message if empty on submit and set to mandatory previously */ $fields[] = array("", "email", "line", "email", "", "Please enter a valid email address"); $fields[] = array("", "replyby", "radio", "{Join|subscribe}{Remove|unsubscribe}", "", "Please select a reply mode"); // ################ END CONFIG ########################################################## // ####################################################################################### $version = "1.3"; function spaces($num, $fill=" "){ $foo=""; for ($i=0; $i<$num; $i++) $foo.=$fill; return $foo; } function isValidEmail($addr){ if(eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$", $addr)) return true; else return false; } // start form evaluation unset($error); if ($_REQUEST['do']=="send"){ $error = false; $fromAddress = ""; $message = ""; foreach ($fields as $field){ if ($field[4] == "*"){ if ($field[3] == "email"){ if (!isValidEmail($_REQUEST[$field[1]])) $error[$field[1]] = $field[5]; }else{ if ($_REQUEST[$field[1]] == "") $error[$field[1]] = $field[5]; } } } if ($error === false){ $message = $emailSubject." \n"; for ($i = 0; $i < strlen($emailSubject); $i++) $message .= "*"; $message .= " \n\n$msgDate:".spaces($msgIndent-strlen($msgDate)).date($dateFormat); foreach ($fields as $field){ $message .= "\n".$field[0]."".spaces($msgIndent-strlen($field[0])); if ($field[3] == "email"){ $message .= "".$_REQUEST[$field[1]]; $fromAddress = "From: ".$_REQUEST[$field[1]]; }else $message .= $_REQUEST[$field[1]]; $message .= " "; } mail($targetAddress, $emailSubject, $message, $fromAddress); echo $txtThankyou; } } if ($error!==false){ // draw form echo "\n\n \n\n"; echo "
\n"; echo "\n"; foreach ($fields as $field){ echo "\n\n"; } echo "\n"; echo "
".$field[0].$field[4]." "; switch ($field[2]){ case "line": echo ""; if (isset($error[$field[1]])) echo "
".$error[$field[1]]."
"; break; case "field": echo ""; if (isset($error[$field[1]])) echo "
".$error[$field[1]]."
"; break; case "radio": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; foreach ($options as $opt){ $opt = explode("|", $opt); $label = $opt[0]; $value = (isset($opt[1])) ? $opt[1] : $opt[0]; $checked = ($_REQUEST[$field[1]] == $value) ? "checked" : ""; echo "   "; $i++; } if (isset($error[$field[1]])) echo "
".$error[$field[1]]."
"; break; case "select": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; echo "\n\n"; if (isset($error[$field[1]])) echo "
".$error[$field[1]]."
"; break; } echo "
 \n"; echo "
\n"; echo "
\n"; echo "\n \n\n"; } /* ######################### END Contact Form ########################## ##################################################################### */ ?>