\n"; /* 2004-10-20 Eric Larson Do not require all fields to be displayed in the email */ /* // Check if all fields are in the field order // BUG: array_diff is not returning keys or values, but the size of the arrray is good $arrDiff = array_diff(array_keys($_POST), explode(",", $strFormFields)); if (count($arrFieldOrder) != count($arrDiff)) { // Display error that field order was not complete display_error("field order did not contain all fields", "ErrorText"); } else */ { for ($i=0; $i < count($arrFieldOrder); $i++) { if (substr(trim($arrFieldOrder[$i]), 0, 1)=="~" && empty($_POST[trim($arrFieldOrder[$i])])) $sMissing .= ", " . substr(trim($arrFieldOrder[$i]), 1, strlen(trim($arrFieldOrder[$i])) - 1); else { $sField = trim($arrFieldOrder[$i]); if (substr($sField, 0, 1) == "~") $sField = substr($sField, 1, strlen($sField) - 1); $sField = str_replace("_", " ", $sField); $strMessage .= $sField . ": " . $_POST[trim($arrFieldOrder[$i])] . "\r\n"; } } } } else { $arrFormFields = explode(",", $strFormFields); foreach (array_keys($_POST) as $sField) { if (substr($sField, 0, 1) == "~" && empty($_POST[$sField])) { $sField = substr($sField, 1, strlen($sField) - 1); $sMissing .= ", " . $sField; } else if (array_search($sField, $arrFormFields) === FALSE) { $sFieldName = $sField; if (substr($sFieldName, 0, 1) == "~") $sFieldName = substr($sFieldName, 1, strlen($sFieldName) - 1); $sFieldName = str_replace("_", " ", $sFieldName); $strMessage .= $sFieldName . ": " . $_POST[$sField] . "\r\n"; } } } // If any fields are missing, prompt if (!empty($sMissing)) { $sMissing = substr($sMissing, 2, strlen($sMissing) - 2); // Display error that required fields were missing display_error($sMissing, "MissingFields"); } else { // Create email $mail = new PHPMailer(); $mail->From = $from; /* $_POST["-from"]; */ /* (isset($_POST[$_POST["-from"]]) ? $_POST[$_POST["-from"]] : $_POST["-from"]) */ $mail->FromName = $fromname; // (isset($_POST[$_POST["-fromfield"]]) ? $_POST[$_POST["-fromfield"]] : $_POST["-fromfield"]); $mail->Subject = $subject; // $_POST["-subject"]; /* (isset($_POST[$_POST["-subject"]]) ? $_POST[$_POST["-subject"]] : $_POST["-subject"]) */ $mail->Body = $strMessage; /* if (isset($_POST[$_POST["-fromfield"]])) { $mail->AddReplyTo($_POST[$_POST["-fromfield"]], $_POST[$_POST["-fromfield"]]); } */ $mail->Host = "mail.infoanalytic.com"; $mail->Mailer = "smtp"; // TO's must be seperated by a comma, already checked not to be null $x = explode(",", $to); for ($i=0; $i < count($x); $i++) { if (validate_email($x[$i]) == 1) $mail->AddAddress(trim($x[$i])); else { // Display bad address error display_error("Invalid email address: " . $x[$i], "MailNotSent"); } } // CC's must be seperated by a comma if (!empty($cc)) { $x = explode(",", $cc); for ($i=0; $i < count($x); $i++) { if (validate_email($x[$i]) == 1) $mail->AddCC(trim($x[$i])); else display_error("Invalid cc email address: " . $x[$i], "MailNotSent"); } } // BCC's must be seperated by a comma if (!empty($bcc)) { $x = explode(",", $bcc); for ($i=0; $i < count($x); $i++) { if (validate_email($x[$i]) == 1) $mail->AddBCC(trim($x[$i])); else display_error("Invalid bcc email address: " . $x[$i], "MailNotSent"); } } // Send Email if(!$mail->Send()) display_error($mail->ErrorInfo, "MailNotSent"); else if (!empty($notify)) { $mail->ClearAllRecipients(); $mail->Subject .= " notification"; if (!empty($_SERVER["HTTP_REFERER"])) $mail->Body = "The form located at " . $_SERVER["HTTP_REFERER"] . " was submitted on " . date("m/d/Y \a\\t h:i:s A") . ".\r\n\r\nNote: Some internet security software (e.g. Norton Internet Security) can alter the referring page sent by the client."; else $mail->Body = "A form was submitted on " . date("m/d/Y \a\\t h:i:s A") . ".\r\n\r\nNote: No referral page was given with the form, which can be the result of some internet security software (e.g. Norton Internet Security) running on the client."; $x = explode(",", $notify); for ($i=0; $i < count($x); $i++) { if (validate_email($x[$i]) == 1) $mail->AddAddress(trim($x[$i])); else display_error("Invalid bcc email address: " . $x[$i], "MailNotSent"); } /* // prompt error? the main one was sent if(!$mail->Send()) { // Display mail sending error display_error($mail->ErrorInfo, "MailNotSent"); } */ $mail->Send(); } // Redirect to response page header("Location: $response"); } } else echo "This script does not allow requests with a " . $_SERVER["REQUEST_METHOD"] . " method."; ?>