From f4380879cde6de625527418819a5a0675d92d821 Mon Sep 17 00:00:00 2001 From: Eric Fawcett Date: Thu, 10 Mar 2022 01:52:27 +0000 Subject: [PATCH] move configuration to sendform.conf --- sendform.conf | 53 +++++++++++++++++++++++++++++ sendform.php | 92 ++++++++++++--------------------------------------- 2 files changed, 74 insertions(+), 71 deletions(-) create mode 100644 sendform.conf diff --git a/sendform.conf b/sendform.conf new file mode 100644 index 0000000..825c914 --- /dev/null +++ b/sendform.conf @@ -0,0 +1,53 @@ + "domain.com", + +// Google reCaptcha v2 secret. Obtain your key from https://www.google.com/recaptcha/admin/create +// Enter your secret key below and be sure to integrate reCaptcha into your site with your site key. +// +// +//
+// +// Leave blank to disable (Not a good idea). +'reCaptchaSecret' => "", + +// 'excludeFields' is a list of field names separated 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 separated 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 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' => ""; + +); +?> \ No newline at end of file diff --git a/sendform.php b/sendform.php index c5b2e9b..f734c81 100644 --- a/sendform.php +++ b/sendform.php @@ -1,63 +1,13 @@ - //
- // - // Leave blank to disable (Not a good idea). - $reCaptchaSecret = ""; + require_once("sendform.conf"); - // $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"; + if ($conf['defaultReq'] != "") $conf['defaultReq'] .= ", recipient"; + else $conf['defaultReq'] = "recipient"; - // $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, g-recaptcha-response, " . $excludeFields); - $srequired = explode(",", $defaultReq); + $conf['referrals'] = explode(",", $conf['referrals']); + $conf['excludeFields'] = explode(",", "recipient, ccrecipient, bccrecipient, subject, required, redirect, mailtemplate, mailtemplatehtml, submit, submit_x, submit_y, verification, ignoreempty, g-recaptcha-response, " . $conf['excludeFields']); + $srequired = explode(",", $conf['defaultReq']); $errMsgStyle = "font-family: Arial; font-size: 14px; @@ -75,12 +25,12 @@ checkreferal(); // Google reCaptcha v2 - if(isset($reCaptchaSecret)){ + if(isset($conf['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); + $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($conf['reCaptchaSecret']) . '&response=' . urlencode($captcha); $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); @@ -98,23 +48,23 @@ } checkrequired(); - if(!validemail($defaultFrom) && !isset($_POST['email'])) bademail($defaultFrom); + if(!validemail($conf['defaultFrom']) && !isset($_POST['email'])) bademail($conf['defaultFrom']); fillrecipients(); if(isset($_POST['subject'])) $subject = $_POST['subject']; else - $subject = $defaultSubject; + $subject = $conf['defaultSubject']; if(isset($_POST['ignoreempty']) && ($_POST('ignoreempty') === true || $_POST('ignoreempty') === false)) $ignoreempty = $_POST['ignoreempty']; else - $ignoreempty = $defaultIgnoreEmpty; + $ignoreempty = $conf['defaultIgnoreEmpty']; if(isset($_POST['email']) && trim($_POST['email']) != "") $fromemail = $_POST['email']; else - $fromemail = $defaultFrom; + $fromemail = $conf['defaultFrom']; if(isset($_POST['redirect'])) @@ -168,19 +118,19 @@ } function sendit() { - global $recipients, $subject, $message, $fromemail, $headers, $smtpHost, $smtpUser, $smtpPass, $smtpEnable; + global $recipients, $subject, $message, $fromemail, $headers, $conf['smtpHost'], $conf['smtpUser'], $conf['smtpPass'], $conf['smtpEnable']; foreach($recipients as $to) { - if($smtpEnable == 1){ + if($conf['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)); + $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $conf['smtpUser'], 'password' => $conf['smtpPass'])); $mail = $smtp->send($to, $headers, $message); if (PEAR::isError($mail)) errormsg($mail->getMessage()); } - elseif($smtpEnable == 0){ + elseif($conf['smtpEnable'] == 0){ if(trim($to) != "") mail(trim($to), stripslashes($subject), stripslashes($message), $headers); } @@ -233,8 +183,8 @@ function exclude($theVar) { $req = false; - global $excludeFields; - foreach($excludeFields as $field) { + global $conf['excludeFields']; + foreach($conf['excludeFields'] as $field) { $field = trim($field); if(strcmp(strtolower($field), strtolower($theVar)) == 0) $req = true; @@ -242,9 +192,9 @@ return $req; } function checkreferal() { - global $referals, $theDomain; + global $conf['referrals'], $theDomain; $valid = false; - foreach($referals as $ref) { + foreach($conf['referrals'] as $ref) { $ref = trim($ref); if(strcmp($theDomain, $ref) == 0) { $valid = true; @@ -255,7 +205,7 @@ badreferer($theDomain); } function errormail($errormsg) { - if (validemail($errorTo)) mail($errorTo, 'Error on form', $errormsg, $headers); + if (validemail($conf['errorTo'])) mail($conf['errorTo'], 'Error on form', $errormsg, $headers); } function fillrecipients() { global $recipients;