//
// // Leave blank to disable (Not a good idea). $reCaptchaSecret = ""; // $excludeFields is a list of field names seperated by commas. Field names listed here will not // be included in the resulting email of this script. // NOTE: The fields "recipient, subject, required, redirect, mailtemplate, mailtemplatehtml" are // used by this script and are automagically added later in the script. $excludeFields = ""; // $defaultFrom is an email address in proper form. This is the default from address used to send // mail if there is no field "email" sent to this script. $defaultFrom = 'sendform@domain.com'; // $defaultSubject is a String. This is the default subject used if there is no field "subject" // sent to this script. $defaultSubject = "SendForm Results"; // $defaultReq is a list of field names seperated by commas. Field names listed here are assumed // required for the script to run. // NOTE: The field "recipient" is required by this script and will always be checked. $defaultReq = ""; // $defaultIgnoreEmpty is either true or false. If true, the script will ignore all empty fields // and return only fields that contain data. Useful if you have a number optional fields and do not // want to output them to the resulting email. $defaultIgnoreEmpty = false; // $smtpEnable enables or disables the SMTP sending method. enter 1 to turn it on or 0 to turn it off // $smtpHost, $smtpUser, $smtpPass only need to be filled if $smtpEnable is set to 1 $smtpEnable = "0"; $smtpHost = "mail.server.com"; $smtpUser = "johndoe@domain.com"; $smtpPass = "passwerd"; // $errorTo is a valid email address that will receive a simple notification for each error that occurs. // Leave blank to turn off. NOTE: this function does not support the SMTP sending method. $errorTo = ""; /************************************************************************ * DO NOT EDIT BELOW THIS LINE * * unless you know what you are doing * ************************************************************************/ if ($defaultReq != "") $defaultReq .= ", recipient"; else $defaultReq = "recipient"; $referals = explode(",", $referals); $excludeFields = explode(",", "recipient, ccrecipient, bccrecipient, subject, required, redirect, mailtemplate, mailtemplatehtml, submit, submit_x, submit_y, verification, ignoreempty, " . $excludeFields); $srequired = explode(",", $defaultReq); $errMsgStyle = "font-family: Arial; font-size: 14px; color: #FF0000; font-weight: bold; width: 100%; text-align: center;"; $errDetStyle = "font-family: Arial; font-size: 12px; color: #FF0000; width: 100%; text-align: center;"; $theDomain = getdomain($_SERVER['HTTP_REFERER']); checkreferal(); // Google reCaptcha v2 if(isset($reCaptchaSecret)){ if(isset($_POST['g-recaptcha-response'])) $captcha=$_POST['g-recaptcha-response']; else errormsg("Verification failed. Please try again."); // post request to server $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($reCaptchaSecret) . '&response=' . urlencode($captcha); $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $response = curl_exec($ch); curl_close($ch); $responseKeys = json_decode($response,true); // should return JSON with success as true if(!$responseKeys["success"]) errormsg("Verification failed. Please try again."); } checkrequired(); if(!validemail($defaultFrom) && !isset($_POST['email'])) bademail($defaultFrom); fillrecipients(); if(isset($_POST['subject'])) $subject = $_POST['subject']; else $subject = $defaultSubject; if(isset($_POST['ignoreempty']) && ($_POST('ignoreempty') === true || $_POST('ignoreempty') === false)) $ignoreempty = $_POST['ignoreempty']; else $ignoreempty = $defaultIgnoreEmpty; if(isset($_POST['email']) && trim($_POST['email']) != "") $fromemail = $_POST['email']; else $fromemail = $defaultFrom; if(isset($_POST['redirect'])) $redirectURL = $_POST['redirect']; else $redirectURL = $_SERVER['HTTP_REFERER']; if(isset($_POST['mailtemplate']) && $_POST['mailtemplate'] != "") writetemplate($_POST['mailtemplate']); else { if(isset($_POST['mailtemplatehtml']) && $_POST['mailtemplatehtml'] != "") { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; writetemplate($_POST['mailtemplatehtml']); } else writestandard(); } $headers .= "From: $fromemail" . "\r\n"; if(isset($_POST['ccrecipient']) && $_POST['ccrecipient'] != ""){ $ccemail = $_POST['ccrecipient']; $headers .= "Cc: $ccemail" . "\r\n"; } if(isset($_POST['bccrecipient']) && $_POST['bccrecipient'] != ""){ $bccemail = $_POST['bccrecipient']; $headers .= "Bcc: $bccemail" . "\r\n"; } sendit(); redirect(); function checkrequired() { global $recipients, $subject, $phone, $fax, $email,$redirectURL, $message, $srequired, $urequired; // Check for all script required fields foreach($srequired as $req) { $req = trim($req); if(!isset($_POST[$req])) missingfield($req); } // Check for all user required fields if(isset($_POST['required'])) { $urequired = explode(",", "recipient, " . $_POST['required']); foreach($urequired as $req) { $req = trim($req); if($req == "email" && isset($_POST[$req]) && !validemail($_POST[$req])) bademail($_POST[$req]); else if(!isset($_POST[$req]) || trim($_POST[$req]) == "") missingfield($req); } } } function sendit() { global $recipients, $subject, $message, $fromemail, $headers, $smtpHost, $smtpUser, $smtpPass, $smtpEnable; foreach($recipients as $to) { if($smtpEnable == 1){ require_once "Mail.php"; $headers = array ('From' => $fromemail, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $smtpUser, 'password' => $smtpPass)); $mail = $smtp->send($to, $headers, $message); if (PEAR::isError($mail)) errormsg($mail->getMessage()); } elseif($smtpEnable == 0){ if(trim($to) != "") mail(trim($to), stripslashes($subject), stripslashes($message), $headers); } } } function writestandard() { global $message, $theDomain, $ignoreempty; $message="Here is the information collected:\n\n"; foreach($_POST as $varname => $varval) { if($ignoreempty===true && empty($varval)) continue; if(is_array($varval)) $varval = implode(", ",$varval); if(!exclude($varname)) { $message .= "$varname: "; if(count($varval) > 1) { for($i = 0; $i < count($varval); $i++) if($i < count($varval) - 1) $message .= "$varval[$i], "; else $message .= "$varval[$i]"; } else { $message .= "$varval"; } $message .= "\n"; } } } function writetemplate($thefile) { global $message, $theDomain, $ignoreempty; $thearray = Array(); if($fp = @fopen($thefile, 'r')) { while($data = fgets($fp, 1024)) { $data = chop($data); foreach($_POST as $varname => $varval) { if($ignoreempty===true && empty($varval)) continue; if(is_array($varval)) $varval = implode(", ",$varval); $data = str_replace("[$varname]", $varval, $data); } $message .= $data . "\n"; } fclose($fp); } } function redirect() { global $redirectURL; header("Location: " . $redirectURL); } function exclude($theVar) { $req = false; global $excludeFields; foreach($excludeFields as $field) { $field = trim($field); if(strcmp(strtolower($field), strtolower($theVar)) == 0) $req = true; } return $req; } function checkreferal() { global $referals, $theDomain; $valid = false; foreach($referals as $ref) { $ref = trim($ref); if(strcmp($theDomain, $ref) == 0) { $valid = true; break; } } if(!$valid) badreferer($theDomain); } function errormail($errormsg) { if (validemail($errorTo)) mail($errorTo, 'Error on form', $errormsg, $headers); } function fillrecipients() { global $recipients; $recipients = explode(",", $_POST['recipient']); } function missingfield($field) { writeStyles(); echo "

Missing Required Field

\n"; echo "

"; echo "The Missing Field:"; echo "$field"; echo "

"; errormail("The Missing Field:".$field); exit; } function badreferer($ref) { writeStyles(); echo "

Bad Referer

\n"; echo "

"; echo "This domain is not authorized for use of this script:"; echo "$ref"; echo "

"; errormail("This domain is not authorized for use of this script:".$ref); exit; } function bademail($email) { writeStyles(); echo "

Bad EMail Address

"; echo "

"; echo "The email address you provided is not a valid email address:"; echo "$email"; echo "

"; errormail("The email address you provided is not a valid email address:".$email); exit; } function errormsg($msg) { writeStyles(); echo "

An Error Has Occured

"; echo "

"; echo "$msg"; echo "

"; errormail("An Error Has Occured:".$msg); exit; } function getdomain($url) { $host = parse_url($url, PHP_URL_HOST); $host = preg_replace("(www\.)","",$host); return $host; #preg_match("/^(http:\/\/)?([^\/]+)/i", $url, $matches); #$host = $matches[2]; #preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); #return $matches[0]; } function validemail($email) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) return true; else return false; } function writeStyles() { global $errMsgStyle, $errDetStyle; echo ""; } ?>