Mailer option => 'smtp' || 'sendmail' || 'mail'(?) $SUBMIT_BUTTON_NAME = 'submit_button'; # this is a submission, not a form request? # admin mail $ADMIN_EMAIL = array(); $ADMIN_NAME = array(); $GENERATE_ADMIN_EMAIL = true; # generate the email body from input $GENERATE_USER_EMAIL = true; # generate the email body from input # none for user mail $USER_EMAIL = ''; $USER_SUBJECT = 'Your Form Submission'; # CSV $CSV_FILE = "$MAILER_CWD/data.csv"; # set to "" to ignore CSV # :var:, $_SERVER keys, 'raw text', or form fields $CSV_FORMAT = ""; $CSV_SEP_CHAR = ","; $CSV_QUOTE_CHAR = '"'; $CSV_QUOTE_ESCAPE_CHAR = '"'; $CSV_JOIN_CHAR = "&"; # for multiple-value field concatenation # this requires that there be an extension and that the conf files are in the dir named # after the form file, but without that ext. $conf_dir = preg_replace('/^(.+)\..+$/', '$1', $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/'.basename($_SERVER['PHP_SELF'])).'-mailer'; $conf_filename = "$conf_dir/mailer.conf.php"; if (!file_exists($conf_filename)) { $DEBUG = true; debug("failed to find the conf file '$conf_filename'"); exit; } require($conf_filename); $TEMPLATES_DIR = $conf_dir; # are we in test mode? if (isset($INPUT['mailer_test'])) { handleMailerTest($INPUT['mailer_test']); } # check that config vars are set to reasonable things, otherwise die checkConfigurationSanity(); $admin_sent = false; $user_sent = false; if ($_SERVER['REQUEST_METHOD'] == 'POST' || (isset($INPUT[$SUBMIT_BUTTON_NAME]) || isset($INPUT[$SUBMIT_BUTTON_NAME.'_x']))) { // these will populate the $ERRORS array with any errors checkRequiredFields(); $requiredFieldsOk = count($ERRORS) == 0; $meetsGeneralRequirements = meetsGeneralRequirements(); // captcha # good input? if ($requiredFieldsOk && $meetsGeneralRequirements) { debug("(\$requiredFieldsOk && \$meetsGeneralRequirements) is true --> processing input"); // make any final changes to the data // before sending the emails and writing data to the logfile fixInput(); if ((is_string($ADMIN_EMAIL) && $ADMIN_EMAIL != '') || (is_array($ADMIN_EMAIL) && count($ADMIN_EMAIL) > 0)) { debug("\$ADMIN_EMAIL is 'true' --> calling sendAdminEmail()"); $admin_sent = sendAdminMail(); } else { debug("\$ADMIN_EMAIL is 'false' --> not sending admin email"); $admin_sent = true; } # send user mail? if ($USER_EMAIL) { debug("\$USER_EMAIL ($USER_EMAIL) is true --> calling sendUserEmail()"); $user_sent = sendUserMail(); } else { debug("no \$USER_EMAIL means no user email will be sent"); $user_sent = true; } # store to CSV? if ($CSV_FILE) { debug("\$CSV_FILE ($CSV_FILE) is true --> calling storeCSV()"); storeCSV(); } else { debug("\$CSV_FILE ($CSV_FILE) is false --> not storing to CSV"); } # sending ok? if ($admin_sent && $user_sent) { # do something on success onSuccess(); # say thanks if ($SUCCESS_URL) { debug("\$SUCCESS_URL ($SUCCESS_URL) is true --> redirecting"); header("Location: $SUCCESS_URL"); } else { debug("\$SUCCESS_URL ($SUCCESS_URL) is false --> showing form page ($FORMPAGE_FILENAME)"); echo getPopulated($FORMPAGE_FILENAME,array('dummydfgf'=>'Thank you. Your input has been received.')); } } # sending error! else { debug("ERROR sending mail --> showing form page ($FORMPAGE_FILENAME) with error message"); echo getPopulated($FORMPAGE_FILENAME,array('dummydfgf'=>'There was an error sending the mail. Please try again later.')); } } # bad input else { debug("bad input --> showing form page ($FORMPAGE_FILENAME) with error messages"); echo getPopulated($FORMPAGE_FILENAME,$ERRORS); } } # no input else { debug("no input --> showing form page ($FORMPAGE_FILENAME)"); echo getUnpopulated($FORMPAGE_FILENAME); } ?>