move configuration to sendform.conf
This commit is contained in:
parent
285d66b5f1
commit
f4380879cd
|
|
@ -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' => "";
|
||||
|
||||
);
|
||||
?>
|
||||
92
sendform.php
92
sendform.php
|
|
@ -1,63 +1,13 @@
|
|||
<?php
|
||||
session_start();
|
||||
// $referals is a list of web site domains seperated by commas. Only requests originating from
|
||||
// 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 = "";
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue