Quote:
// -------------------------------------------------------------------------------------------------------------------------------
// IMPORT AND PROCESS FORM...
// -------------------------------------------------------------------------------------------------------------------------------
// Import special formatting fields if used...
$recipient = (isset($MPPostVars['recipient'])) ? $MPPostVars['recipient'] : "";
$subject = (isset($MPPostVars['subject'])) ? $MPPostVars['subject'] : "";
$required = (isset($MPPostVars['required'])) ? $MPPostVars['required'] : "";
$redirect = (isset($MPPostVars['redirect'])) ? $MPPostVars['redirect'] : "";
$redirect_type = (isset($MPPostVars['redirect_type'])) ? $MPPostVars['redirect_type'] : "query";
$sort = (isset($MPPostVars['sort'])) ? $MPPostVars['sort'] : "";
$exclude = (isset($MPPostVars['exclude'])) ? $MPPostVars['exclude'] : "";
$exclude_display = (isset($MPPostVars['exclude_display'])) ? $MPPostVars['exclude_display'] : "";
$exclude_email = (isset($MPPostVars['exclude_email'])) ? $MPPostVars['exclude_email'] : "";
$force_match = (isset($MPPostVars['force_match'])) ? $MPPostVars['force_match'] : "";
$recipient_name = (isset($MPPostVars['recipient_name'])) ? $MPPostVars['recipient_name'] : "";
$sender_name = (isset($MPPostVars['sender_name'])) ? $MPPostVars['sender_name'] : "";
$sender_email = (isset($MPPostVars['sender_email'])) ? $MPPostVars['sender_email'] : "";
$numbers_only = (isset($MPPostVars['numbers_only'])) ? $MPPostVars['numbers_only'] : "";
$letters_only = (isset($MPPostVars['letters_only'])) ? $MPPostVars['letters_only'] : "";
$email_only = (isset($MPPostVars['email_only'])) ? $MPPostVars['email_only'] : "";
$uppercase = (isset($MPPostVars['uppercase'])) ? $MPPostVars['uppercase'] : "";
$lowercase = (isset($MPPostVars['lowercase'])) ? $MPPostVars['lowercase'] : "";
$link_text = (isset($MPPostVars['link_text'])) ? $MPPostVars['link_text'] : "";
$link_url = (isset($MPPostVars['link_url'])) ? $MPPostVars['link_url'] : "";
// Attempt to detect and eliminate spamming attempts...
if (isset($evilFound)) unset($evilFound);
function MPSeeNoEvil($string) {
$results = true;
$string = trim(strtolower($string));
$string = stripslashes($string);
$string = str_replace("\r\n", "[evil]", $string);
$string = str_replace("\r", "[evil]", $string);
$string = str_replace("\n", "[evil]", $string);
$string = str_replace("bcc:", "[evil]", $string);
$string = str_replace("cc:", "[evil]", $string);
if (stristr($string, '[evil]') !== false) $results = false;
return $results;
}
if (!MPSeeNoEvil($subject)) $errors .= "This submission appears to be a spamming attempt.<br>$li";
if (!MPSeeNoEvil($recipient_name)) $errors .= "This submission appears to be a spamming attempt.<br>$li";
if (isset($MPPostVars[$sender_name])) if (!MPSeeNoEvil($MPPostVars[$sender_name]))
$errors .= "This submission appears to be a spamming attempt.<br>$li";
if (isset($MPPostVars[$sender_email])) if (!MPSeeNoEvil($MPPostVars[$sender_email]))
$errors .= "This submission appears to be a spamming attempt.<br>$li";
$ip = (isset($MPServerVars['REMOTE_ADDR'])) ? $MPServerVars['REMOTE_ADDR'] : '';
if ($MPSendIP) $MPPostVars['visitor_IP'] = $ip;
if ($MPCheckIP) {
if (in_array($ip, $badIPs))
$errors .= "This IP address ($ip) has been blacklisted due to spamming attempts.<br>$li";
}
if ($MPHideIP) {
if ($exclude_display == '') $exclude_display = 'visitor_IP';
else $exclude_display .= ', visitor_IP';
}
// Verify the "recipient" field...
if ($recipient == "") {
if ($write_to_mysql == "" AND $write_to_file == "")
$errors .= "No \"recipient\" field was included, or the \"recipient\" value was empty.<br>$le";
} else {
$recipKeys = explode(",", $recipient);
$recipientArray = array();
for ($n=0; $n<count($recipKeys); $n++) {
$thisRecipKey = $recipKeys[$n];
if ($thisRecipKey != '') {
$thisRecipValue = $recipients[$thisRecipKey];
if ($thisRecipValue == "" OR $thisRecipValue == "email_address_here" OR $thisRecipValue == "address@yourdomain.com")
$errors .= "No email address was found in the recipients list with key number \"$thisRecipKey\"<br>$le";
else $recipientArray[] = $thisRecipValue;
}
}
if (count($recipientArray) < 1)
$errors .= "No \"recipient\" field was included, or the \"recipient\" value was empty.<br>$le";
}
// Verify "required" fields if specified...
if ($required != "") {
$reqErrors = "";
$requiredFields = explode(",", $required);
for ($n=0; $n<count($requiredFields); $n++) {
$tempName = trim($requiredFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$thisReqField = $tempName;
$fieldValid = false;
if (isset($MPPostVars[$thisReqField])) {
if ($MPPostVars[$thisReqField] != "") $fieldValid = true;
} else if (isset($MPPostFiles[$thisReqField])) {
if (is_uploaded_file($MPPostFiles[$thisReqField]['tmp_name'])) $fieldValid = true;
}
if ($fieldValid == false) $reqErrors .= "<li><span class=\"MPerrorlist\">".MPAdjustFields($thisReqField)."</span></li>$le";
}
if ($reqErrors != "") $errors .= $reqErrMsg."<ul class=\"MPerrorlist\">".$reqErrors." </ul>";
}
// Convert field values to uppercase if specified...
if ($uppercase != "") {
$ucFields = explode(",", $uppercase);
for ($n=0; $n<count($ucFields); $n++) {
$tempName = trim($ucFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
if (isset($MPPostVars[$tempName])) {
$tempValue = strtoupper($MPPostVars[$tempName]);
$MPPostVars[$tempName] = $tempValue;
}
}
}
// Convert field values to lowercase if specified...
if ($lowercase != "") {
$lcFields = explode(",", $lowercase);
for ($n=0; $n<count($lcFields); $n++) {
$tempName = trim($lcFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
if (isset($MPPostVars[$tempName])) {
$tempValue = strtolower($MPPostVars[$tempName]);
$MPPostVars[$tempName] = $tempValue;
}
}
}
// Verify formatting for email fields if specified...
if ($email_only != "") {
$emailFields = explode(",", $email_only);
for ($n=0; $n<count($emailFields); $n++) {
$tempName = trim($emailFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
if (isset($MPPostVars[$tempName])) {
$thisTest = $MPPostVars[$tempName];
if (!eregi($emailPattern, $thisTest))
$errors .= str_replace("[email field]", MPAdjustFields($tempName), $emailErrMsg)."<br>";
}
}
}
// Verify formatting for number fields if specified...
if ($numbers_only != "") {
$numberFields = explode(",", $numbers_only);
for ($n=0; $n<count($numberFields); $n++) {
$tempName = trim($numberFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
if (isset($MPPostVars[$tempName])) {
$thisTest = str_replace(",", "", $MPPostVars[$tempName]);
if (!eregi($numberPattern, $thisTest))
$errors .= str_replace("[number field]", MPAdjustFields($tempName), $numErrMsg)."<br>";
else $MPPostVars[$tempName] = $thisTest;
}
}
}
// Verify formatting for letter fields if specified...
if ($letters_only != "") {
$letterFields = explode(",", $letters_only);
for ($n=0; $n<count($letterFields); $n++) {
$tempName = trim($letterFields[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
if (isset($MPPostVars[$tempName])) {
$thisTest = $MPPostVars[$tempName];
if (!eregi($letterPattern, $thisTest))
$errors .= str_replace("[letter field]", MPAdjustFields($tempName), $letterErrMsg)."<br>";
}
}
}
// Compare "force_match" fields if specified...
if ($force_match != "") {
$allFound = true;
$matchFields = explode(";", $force_match);
for ($n=0; $n<count($matchFields); $n++) {
$tempName = trim($matchFields[$n]);
$matchFields[$n] = $tempName;
if ($matchFields[$n] != "") {
$thisMatchField = trim($matchFields[$n]);
$thisMatchField = explode(",", $thisMatchField);
$fieldsMatch = true;
$matchTest = "";
for ($i=0; $i<count($thisMatchField); $i++) {
if ($thisMatchField[$i] != "") {
$tempName = trim($thisMatchField[$i]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$thisMatchField[$i] = trim($tempName);
$tempField = $thisMatchField[$i];
if ($matchTest == "") $matchTest = $MPPostVars[$tempField];
else {
$tempValue = (isset($MPPostVars[$tempField])) ? $MPPostVars[$tempField] : "";
if ($tempValue != $matchTest) $fieldsMatch = false;
}
}
}
if ($fieldsMatch == false AND is_array($thisMatchField)) {
$tempString = implode(", ", $thisMatchField);
$errors .= $matchErrMsg."<br><span class=\"MPerrorlist\">".MPAdjustFields($tempString)."</span><br>";
}
}
}
}
// Verify and process "sort" field if specified...
if ($sort != "") {
$formArray = "";
$x = 0;
$sortArray = explode(",", $sort);
for ($n=0; $n<count($sortArray); $n++) {
$tempName = trim($sortArray[$n]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$thisPair["key"] = $tempName;
if (isset($MPPostVars[$thisPair["key"]])) {
$thisPair["value"] = stripslashes(MPFixArrays($MPPostVars[$thisPair["key"]]));
$formArray[$x] = $thisPair;
$x++;
}
}
// If no sort order was specified, bring in all form fields in the default order...
} else {
reset($MPPostVars);
$n = 0;
while($thisPair = each($MPPostVars)) {
$thisPair["value"] = stripslashes(MPFixArrays($thisPair["value"]));
$formArray[$n] = $thisPair;
$n++;
}
}
// Strip out "exclude" field names from $formArray...
$excludeFields = "recipient,redirect,redirect_type,required,sort,exclude,subject,exclude_dis play,sender_name,sender_email,";
$excludeFields .= "exclude_email,force_match,recipient_name,write_to_file,force_format,upperc ase,lowercase,link_text,link_url,";
$excludeFields .= "write_to_mysql,mysql_table,mysql_update_field,mysql_update_value,numbers_o nly,letters_only,email_only,SubmitButtonName,Submit,captcha_entered,captcha _encoded";
if ($exclude != "") $excludeFields .= ",$exclude";
$excludeArray = explode(",", $excludeFields);
$tempArray = array();
for ($n=0; $n<count($formArray); $n++) {
$formArray[$n]['key'] = trim($formArray[$n]['key']);
$excludeHits = false;
for ($i=0; $i<count($excludeArray); $i++) {
$tempName = trim($excludeArray[$i]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$excludeArray[$i] = $tempName;
if ($formArray[$n]['key'] == $excludeArray[$i]) $excludeHits = true;
}
if ($excludeHits == false) $tempArray[] = $formArray[$n];
}
$formArray = $tempArray;
// Strip out "exclude_display" fields if specified and build display array...
if ($exclude_display != "") {
$displayArray = array();
$exDisArray = explode(",", $exclude_display);
for ($n=0; $n<count($formArray); $n++) {
$formArray[$n]['key'] = trim($formArray[$n]['key']);
$excludeHits = false;
for ($i=0; $i<count($exDisArray); $i++) {
$tempName = trim($exDisArray[$i]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$exDisArray[$i] = $tempName;
if ($formArray[$n]['key'] == $exDisArray[$i]) $excludeHits = true;
}
if ($excludeHits == false) $displayArray[] = $formArray[$n];
}
} else $displayArray = $formArray;
// Strip out "exclude_email" fields if specified and build email array...
if ($exclude_email != "") {
$emailArray = array();
$exEmailArray = explode(",", $exclude_email);
for ($n=0; $n<count($formArray); $n++) {
$formArray[$n]['key'] = trim($formArray[$n]['key']);
$excludeHits = false;
for ($i=0; $i<count($exEmailArray); $i++) {
$tempName = trim($exEmailArray[$i]);
$last2Chars = substr($tempName, (strlen($tempName)-2), 2);
if ($last2Chars == "[]") $tempName = substr($tempName, 0, (strlen($tempName)-2));
$exEmailArray[$i] = $tempName;
if ($formArray[$n]['key'] == $exEmailArray[$i]) $excludeHits = true;;
}
if ($excludeHits == false) $emailArray[] = $formArray[$n];
}
} else $emailArray = $formArray;
// If no subject was specified, set it to the default...
$MPSubject = ($subject == "") ? "Web Form Submission" : stripslashes($subject);
$headers = "MIME-Version: 1.0$le";
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"$le";
$headers .= "Content-Transfer-Encoding: 7bit";
if ($errors == "") {
// Send out email if recipients were found...
if ($recipient != "") {
$recipientString = implode(", ", $recipientArray);
$MPEmailBody = "The following information was submitted on $dateTime:$le$le";
$MPEmailBody .= "-------------------------------------------------------$le$le";
$emailSepChars = ($doubleSpaceEmail == true) ? "$le$le" : "$le";
$emailNameVals = "";
for ($n=0; $n<count($emailArray); $n++) {
if ($emailArray[$n]['value'] != "") {
$thisFieldName = MPAdjustFields(stripslashes($emailArray[$n]['key']));
$thisFieldValue = stripslashes($emailArray[$n]['value']);
$emailNameVals .= $thisFieldName.": ".$thisFieldValue.$emailSepChars;
}
}
$MPEmailBody .= $emailNameVals;
$MPEmailBody .= "-------------------------------------------------------$le $le";
$MPSender = "";
$sender_email = (isset($MPPostVars[$sender_email])) ? $MPPostVars[$sender_email] : "";
if ($sender_email != "") $sender_email = (eregi($emailPattern, $sender_email)) ? $sender_email : "";
$sender_name = (isset($MPPostVars[$sender_name])) ? $MPPostVars[$sender_name] : "";
if ($sender_email != "") {
$MPSender = ($sender_name != "") ? stripslashes($sender_name)." <".stripslashes($sender_email).">" : stripslashes($sender_email);
}
if ($MPSender != "") $MPSender = "From: $MPSender$le";
if ($MPForceSender != "") $MPSender = "From: $MPForceSender$le";
$headers = $MPSender.$headers;
@$mailStatus = mail($recipientString, $MPSubject, $MPEmailBody, $headers);
if (!$mailStatus) $errors .= $mailErrMsg."<br>";
}
// Redirect if specified, adding query string to URL with form results for extraction...
if ($redirect != "") {
$printHTML = false;
if ($redirect_type == "include") {
include("$redirect");
} else if ($redirect_type == "query") {
$queryArray = "";
$q = 0;
for ($n=0; $n<count($displayArray); $n++) {
if ($displayArray[$n]['value'] != "") {
$queryPair = MPParseRedirectData($displayArray[$n]['key'])."=".MPParseRedirectData($displayArray[$n]['value']);
if ($queryPair != "=") {
$queryArray[$q] = $queryPair;
$q++;
}
}
}
$redirectPage = "Location: $redirect";
if (is_array($queryArray)) $redirectPage .= "?".implode("&", $queryArray);
header($redirectPage);
exit;
} else {
header("Location: $redirect");
exit;
}
}
}
}
// -------------------------------------------------------------------------------------------------------------------------------
// PRINT HTML FOR DEFAULT AND CONFIRMATION PAGES...
// -------------------------------------------------------------------------------------------------------------------------------
// if not redirecting, start printing HTML response page...
if ($printHTML == true OR $formSubmitted == false) {
print('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Form Results</title>
<style type="text/css" media="screen"><!--
body, div, td, p { '.$pageStyle.' }
.MPinfo { '.$MPinfo.' }
.MPFieldNames { '.$MPFieldNames.' }
.MPFieldValues { '.$MPFieldValues.' }
.MPthankyou { '.$MPthankyou.' }
.MPerror { '.$MPerror.' }
.MPerrorlist { '.$MPerrorlist.' }
.MPsmall { '.$MPsmall.' }
.MPsubhead { '.$MPsubhead.' }
.MPlink { '.$MPlink.' }
.MPlink a:link { '.$MPlink.' }
.MPlink a:visited { '.$MPlink.' }
.MPlink a:hover { '.$MPlink_hover.' }
.MPcredit { '.$MPcredit.' }
--></style>
</head>
<body>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
');
// If there were errors, list them...
if ($errors != "") {
print("
<td align=\"left\" valign=\"top\">
<br> <br><span class=\"MPerror\">$errors</span><br> <br>
</td>
</tr>
<tr>
<td align=\"center\" valign=\"top\" class=\"MPinfo\">
[ <span class=\"MPlink\"><a href=\"javascript:history.back();\">back to form</a></span> ]<br>
<br>
<span class=\"MPsmall\">(If JavaScript is disabled, use the back button on your browser.)</span><br>
");
// If no errors were encountered, list emailed results and home link if specified...
} else if ($formSubmitted == true) {
if ($recipient == "") $sentTo = "this page";
else $sentTo = ($recipient_name != "") ? $recipient_name : $recipientString;
$sentToMsg = str_replace("[message recipient]", $sentTo, $confirmMsgText);
print("
<td align=\"center\" valign=\"top\" width=\"570\">
<br>
<span class=\"MPthankyou\">$confirmMsgTitle</span><br>
<span class=\"MPsubhead\">$sentToMsg<br>
($dateTime)</span><hr>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">
");
for ($n=0; $n<count($displayArray); $n++) {
if ($displayArray[$n]['value'] != "") {
$htmlPair = MPNameValueHTML($displayArray[$n], "MPFieldNames", "MPFieldValues");
$thisFieldName = $htmlPair[0];
$thisFieldValue = $htmlPair[1];
print("<tr>$le<td align=\"right\" valign=\"top\" nobreak>".$thisFieldName." </td>$le");
print("<td align=\"left\" valign=\"top\">".$thisFieldValue."</td>$le<tr>$le");
}
}
print("</table>$le<hr>$le");
if ($link_url != "" AND $link_url != "http://") {
if ($link_url == "close") {
$link_url = "javascript:self.close();";
if ($link_text == "") $link_text = "close window";
} else if ($link_url == "back") {
$link_url = "javascript:history.back();";
if ($link_text == "") $link_text = "back to form";
} else {
if (substr($link_url, 0, 7) != "http://") $link_url = "http://".$link_url;
$link_text = ($link_text != "") ? $link_text : "back to home";
}
print("[ <span class=\"MPlink\"><a href=\"$link_url\">$link_text</a></span> ]<br>$le <br>$le");
}
} else {
print("
<br> <br><span class=\"MPthankyou\">NateMail 3.0.15 PHP Script</span><br>
<br>
[ <span class=\"MPlink\"><a href=\"http://www.mindpalette.com/scripts/formprocessing\">download page</a></span> ]<br>
");
}
print('<br>
<br>
<span class="MPcredit">NateMail 3.0.15 by Nate Baldwin, www.mindpalette.com</span><br>
</td>
</tr>
</table>
</div>
</body>
</html>');
}
// -------------------------------------------------------------------------------------------------------------------------------
// END OF SCRIPT! NateMail 3.0.15 by Nate Baldwin, www.mindpalette.com - copyright 2006
// -------------------------------------------------------------------------------------------------------------------------------
?>
| Sorry, had to do it in two parts as too many characters. Thanks again!! |