move configuration to sendform.conf

This commit is contained in:
Eric Fawcett 2022-03-10 01:52:27 +00:00
parent 285d66b5f1
commit f4380879cd
2 changed files with 74 additions and 71 deletions

53
sendform.conf Normal file
View File

@ -0,0 +1,53 @@
<?PHP
$conf = array(
// 'referrals' is a list of web site domains separated by commas. Only requests originating from
// these domains will be processed.
'referrals' => "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.
//
// <script src="https://www.google.com/recaptcha/api.js"></script>
// <div class="g-recaptcha" data-sitekey="your_site_key"></div>
//
// 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' => "";
);
?>

View File

@ -1,63 +1,13 @@
<?php <?php
session_start(); session_start();
// $referals is a list of web site domains seperated by commas. Only requests originating from require_once("sendform.conf");
// these domains will be processed.
$referals = "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.
//
// <script src="https://www.google.com/recaptcha/api.js"></script>
// <div class="g-recaptcha" data-sitekey="your_site_key"></div>
//
// 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 if ($conf['defaultReq'] != "") $conf['defaultReq'] .= ", recipient";
// be included in the resulting email of this script. else $conf['defaultReq'] = "recipient";
// 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 $conf['referrals'] = explode(",", $conf['referrals']);
// required for the script to run. $conf['excludeFields'] = explode(",", "recipient, ccrecipient, bccrecipient, subject, required, redirect, mailtemplate, mailtemplatehtml, submit, submit_x, submit_y, verification, ignoreempty, g-recaptcha-response, " . $conf['excludeFields']);
// NOTE: The field "recipient" is required by this script and will always be checked. $srequired = explode(",", $conf['defaultReq']);
$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);
$errMsgStyle = "font-family: Arial; $errMsgStyle = "font-family: Arial;
font-size: 14px; font-size: 14px;
@ -75,12 +25,12 @@
checkreferal(); checkreferal();
// Google reCaptcha v2 // Google reCaptcha v2
if(isset($reCaptchaSecret)){ if(isset($conf['reCaptchaSecret'])){
if(isset($_POST['g-recaptcha-response'])) $captcha=$_POST['g-recaptcha-response']; if(isset($_POST['g-recaptcha-response'])) $captcha=$_POST['g-recaptcha-response'];
else errormsg("Verification failed. Please try again."); else errormsg("Verification failed. Please try again.");
// post request to server // 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(); $ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
@ -98,23 +48,23 @@
} }
checkrequired(); checkrequired();
if(!validemail($defaultFrom) && !isset($_POST['email'])) bademail($defaultFrom); if(!validemail($conf['defaultFrom']) && !isset($_POST['email'])) bademail($conf['defaultFrom']);
fillrecipients(); fillrecipients();
if(isset($_POST['subject'])) if(isset($_POST['subject']))
$subject = $_POST['subject']; $subject = $_POST['subject'];
else else
$subject = $defaultSubject; $subject = $conf['defaultSubject'];
if(isset($_POST['ignoreempty']) && ($_POST('ignoreempty') === true || $_POST('ignoreempty') === false)) if(isset($_POST['ignoreempty']) && ($_POST('ignoreempty') === true || $_POST('ignoreempty') === false))
$ignoreempty = $_POST['ignoreempty']; $ignoreempty = $_POST['ignoreempty'];
else else
$ignoreempty = $defaultIgnoreEmpty; $ignoreempty = $conf['defaultIgnoreEmpty'];
if(isset($_POST['email']) && trim($_POST['email']) != "") if(isset($_POST['email']) && trim($_POST['email']) != "")
$fromemail = $_POST['email']; $fromemail = $_POST['email'];
else else
$fromemail = $defaultFrom; $fromemail = $conf['defaultFrom'];
if(isset($_POST['redirect'])) if(isset($_POST['redirect']))
@ -168,19 +118,19 @@
} }
function sendit() { 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) { foreach($recipients as $to) {
if($smtpEnable == 1){ if($conf['smtpEnable'] == 1){
require_once "Mail.php"; require_once "Mail.php";
$headers = array ('From' => $fromemail, 'To' => $to, 'Subject' => $subject); $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); $mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail)) errormsg($mail->getMessage()); if (PEAR::isError($mail)) errormsg($mail->getMessage());
} }
elseif($smtpEnable == 0){ elseif($conf['smtpEnable'] == 0){
if(trim($to) != "") if(trim($to) != "")
mail(trim($to), stripslashes($subject), stripslashes($message), $headers); mail(trim($to), stripslashes($subject), stripslashes($message), $headers);
} }
@ -233,8 +183,8 @@
function exclude($theVar) { function exclude($theVar) {
$req = false; $req = false;
global $excludeFields; global $conf['excludeFields'];
foreach($excludeFields as $field) { foreach($conf['excludeFields'] as $field) {
$field = trim($field); $field = trim($field);
if(strcmp(strtolower($field), strtolower($theVar)) == 0) if(strcmp(strtolower($field), strtolower($theVar)) == 0)
$req = true; $req = true;
@ -242,9 +192,9 @@
return $req; return $req;
} }
function checkreferal() { function checkreferal() {
global $referals, $theDomain; global $conf['referrals'], $theDomain;
$valid = false; $valid = false;
foreach($referals as $ref) { foreach($conf['referrals'] as $ref) {
$ref = trim($ref); $ref = trim($ref);
if(strcmp($theDomain, $ref) == 0) { if(strcmp($theDomain, $ref) == 0) {
$valid = true; $valid = true;
@ -255,7 +205,7 @@
badreferer($theDomain); badreferer($theDomain);
} }
function errormail($errormsg) { 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() { function fillrecipients() {
global $recipients; global $recipients;