SELECTING A FORM'S EMAIL RECIPIENTS USING FIELDS IN THEIR ACCOUNT RECORD (A FORMS TO GO MODIFICATION) - Jun 26th, 2015


The initial purpose of this recipe is to be able to control an organization’s board of director positions, committee
memberships and easily designate who the chairpersons of committees are and who is to receive email for the various
positions and committees.

To make the board of director positions and committees flexible, I created a multi record editor called “Board Of
Director Positions”. The records in this section have one text field called “Position” and a dragSortOrder field.
NOTE: The records in “Board Of Director Positions” are where the options in the form below come from.

The organization wanted to allow a member to hold more than one position on the board of directors and/or to sit on up
to 3 committees.

So, in the “User Accounts” section there are 3 sets of 3 Board Of Director fields.

A list field for position (1, 2 and 3), a check box for the chairperson of each, and a check box for the designated
email recipient for each.

The Board of Director Position pull down lists fields (board_of_director_position_1, board_of_director_position_2, and
board_of_director_position_3) get their options from the database “board_of_director_positions” with Option Values
from the “num” field, and Option Labels from the Positions Field.

The check box fields (board_of_director_position_1_chair, board_of_director_position_2_chair,
board_of_director_position_3_chair), signify that this person is the chairperson.

The check box fields (board_of_director_position_1_email, board_of_director_position_2_email,
board_of_director_position_3_email) designate the person who gets email for the board position or committee.

I created the basic form, and then used Forms To Go from Bebosoft.com to create the PHP code required to hide email
address values, route email messages, send confirmations, include captcha and generate error checking code.

I then modified the code to pull the appropriate position and email information from the records in the “User
Accounts” section.

I had a bit of trouble getting the code to generate a set of variables until Claire Ryan from Interactive Tools came to
the rescue and suggested the use of a double $ ($$) to create the variables required.

She also shared the idea of including a variable dump to see if variables were actually being generated in response to
an if statement. The following, which checked the President position and it’s associated variable:

The original static code for each position (President is only an example) was in the format:



if ($FTGreason == "President") {

$emailTo = $president;

$emailFrom = FilterCChars("$FTGemail");

$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"UTF-8\"\n"
. "Content-transfer-encoding: 8bit\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

}



She said: “Just before you get to the check if($FTGreason == "President"), add the following code to see if the
variables are being processed correctly:”


var_dump ($FTGreason);
var_dump ("President");
var_dump ($president);
die;



Claire went on to say: “What you should see is some information like string(9) "President". The var_dump will show you
what FTGreason actually is just before it hits this check, and it won't pass and execute the email code if it doesn't
match what you expect it to be. This is by far the most common reason that if statements stop working, and I've been
caught by it so many times it's the first thing I look at when troubleshooting.

The die statement will obviously kill the script so it'll output the var_dump without processing any further.”

OK, back to the recipe code.

***DON'T FORGET TO CHANGE ALL REFERENCES TO GENERIC PATHS AND DOMAIN NAMES TO MATCH YOUR OWN***
*** IF YOU USE NO-REPLY@YOUR_DOMAIN.COM AS THE RETURN EMAIL ADDRESS< AND DON'T SET UP A REAL EMAIL ACCOUNT FOR THAT
ADDRESS AT YOUR DOMAIN, SOME PROVIDERS MAY BLOCK YOUR EMAILS***

Here’s the code for the form that the visitor sees: ( *** Name the contact form page "contact_form.php" *** )


<div align="left"><span class="body-text-bold">USE THIS FORM TO SEND A MESSAGE DIRECTLY TO THE PEOPLE WHO CAN ANSWER
YOUR QUESTION:</span>

<div class="error-text-yellow-italic" align="left"><!--VALIDATIONERROR--></div>
<?php
$names = array();
foreach (
$board_of_director_positionsRecords as $record){
$names[$record['position']]=$record['position'];
}
?>
<form method="post" action="http://www.your_domain.com/master_form_php.php">

<table width="80%" border="0" cellpadding="15">
<tr >
<td width="40%" align="left" valign="middle"><label class="body-text-bold">Who would you like to
contact?</label></td>
<td style="text-align:left" width="60%" align="left" valign="middle"><select name="reason">
<option value="" >...Select...</option>
<?php foreach($names as $name): ?>
<option value="<?php echo $name;?>"><?php echo $name;?></option>
<?php endforeach?>
</select></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="body-text-bold">What's yourFirst Name</td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text" name="first_name"
id="first_name" value="" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="body-text-bold">Your Last Name</td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text" name="last_name"
id="last_name" value="" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="body-text-bold">Your e-mail</td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text" name="email" id="email"
value="" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="body-text-bold">Re-enter your e-mail</td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text" name="email2" id="email2"
value="" /></td>
</tr>
<tr>
<td width="460%" align="left" valign="middle" class="body-text-bold">What's your message</td>
<td style="text-align:left" align="left" valign="middle"><textarea class="textarea" name="message" cols="60"
rows="6" id="message"></textarea></td>
</tr>
<tr>
<td width="40%">
<span class="body-text">To help prove that you're a human,
please enter the characters into the blank box</span>
</td>
<td style="text-align:left" align="left" valign="middle"><img
src="http://www.your_domain.com/master_form_php.php?formstogoimgflt=yes" height="40" width="160"/>&nbsp; &nbsp;
<input type="text" name="verify" id="verify" width="200" value="" /></td></tr>
<tr>
<td colspan="2" align="left" valign="middle"><input type="submit" name="form_submitted" value="Submit Your Message"
/></td>
</tr>
</table>
</form>
</div>


And Here’s the complete code for the PHP page that processes the form, including vcode to accomodate more than one and
0 selected recipients for a position or committee.: ( ***Name the PHP page "master_form_php.php"*** )

NOTE : I've set up a test field called "board_backup_email" in a single record editor called "Common Information" to
contain the backup email address used in case there is no email address chosen for a particular committee or position.
If you choose not to do this, you'll need to replace the board_backup_email field call with a hard coded address.

NOTE: It's tempting to add comments to a script, but in this case, make sure that they are at the end of an existing
line of code and NOT in a new line.

Extra lines in this case can break the page and cause errors that will keep it from working (like cannot modify header
errors, etc.).



<?php
$GLOBALS['SEP_DISABLED'] = 1; ?>
<?PHP
// library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
list(
$board_of_director_positionsRecords, $board_of_director_positionsMetaData) = getRecords(array(
'tableName' => 'board_of_director_positions',
));
$directorposition = array_filter(array_pluck($board_of_director_positionsRecords, 'position'));
list(
$accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => "board_of_director_position_1_email LIKE '%1%' OR board_of_director_position_2_email LIKE '%1%' OR
board_of_director_position_3_email LIKE '%1%' ",
));
list(
$common_informationRecords, $common_informationMetaData) = getRecords(array(
'tableName' => 'common_information',
'allowSearch' => '0',
'limit' => '1',
));
$common_informationRecord = @$common_informationRecords[0]; // get first record
?>
<?php foreach ($directorposition as $actual_position): ?>
<?php foreach ($accountsRecords as $record): ?>
<?php if ($record['board_of_director_position_1:label'] == $actual_position ||
$record['board_of_director_position_2:label'] == $actual_position || $record['board_of_director_position_3:label'] ==
$actual_position): // is there a position selected ?>
<?php $formatted_position = strtolower($actual_position); // format the position ?>
<?PHP $formatted_position = preg_replace('/\s+/', '_', $formatted_position ); ?>
<?PHP $formatted_position = preg_replace('/-/', '_', $formatted_position ); ?>
<?php if ($record['board_of_director_position_1:label'] == $actual_position && $actual_position &&
$record['board_of_director_position_1_email'] == '1'): // is this records email address the one to use ?>
<?php $email_to_use = $record['email']?>
<?php endif ?>
<?php if ($record['board_of_director_position_2:label'] == $actual_position && $actual_position &&
$record['board_of_director_position_2_email'] == '1'): ?>
<?php $email_to_use = $record['email']?>
<?php endif ?>
<?php if ($record['board_of_director_position_3:label'] == $actual_position && $actual_position &&
$record['board_of_director_position_3_email'] == '1'): ?>
<?php $email_to_use = $record['email']?>
<?php endif ?>
<?php $$formatted_position = $email_to_use; // (the $$ is not a typo, it create a variable using the name stored in
$formatted_position and assign it the value in $email_to_use.)?>
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
<?php
define('kOptional', true);
define('kMandatory', false);

define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);

define('kYes', 'yes');
define('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function
CaptchaGenerator() {

if ( (!
function_exists('imagejpeg')) && (!function_exists('imagepng')) ) {
exit;
}

$im = imagecreate(100,40);

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$gray = imagecolorallocate($im, 150, 150, 150);

imagerectangle($im, 0, 0, 25, 39, $gray);
imagerectangle($im, 25, 0, 50, 39, $gray);
imagerectangle($im, 50, 0, 75, 39, $gray);
imagerectangle($im, 75, 0, 99, 39, $gray);

imageline($im, 0, 0, 25, 39, $gray);
imageline($im, 25, 0, 50, 39, $gray);
imageline($im, 50, 0, 75, 39, $gray);
imageline($im, 75, 0, 99, 39, $gray);

imageline($im, 0, 39, 25, 0, $gray);
imageline($im, 25, 39, 50, 0, $gray);
imageline($im, 50, 39, 75, 0, $gray);
imageline($im, 75, 39, 99, 0, $gray);

$c1 = rand(65, 90);
$c2 = rand(65, 90);
$c3 = rand(65, 90);
$c4 = rand(65, 90);
$c5 = rand(65, 90);

$textOut = chr($c1) . ' ' . chr($c2) . ' ' . chr($c3) . ' ' . chr($c4) . ' ' . chr($c5);
$textCaptcha = chr($c1) . chr($c2) . chr($c3) . chr($c4) . chr($c5);

$a = imagestring($im, 5, 11, 13, $textOut, $black);

$fileName = substr(md5($textCaptcha), 0, 12);

$captchaDir = 'verify';

if ( !
is_dir( $captchaDir ) ) {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Access Code Validation Error: directory &quot;verify&quot; not found. Script will
quit now.</body></html>';
exit;
}

if ( !
is_writable( $captchaDir ) ) {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Access Code Validation Error: directory &quot;verify&quot; is not writeable. Script
will quit now.</body></html>';
exit;
}

$handle = opendir( $captchaDir );

while (
$captchaFile = readdir($handle) ) {
if ( (
substr($captchaFile, 0, 1) != '.' ) && ( substr($captchaFile, 0, 1) != '_' ) && ( !is_dir( 'verify' . '/' .
$captchaFile ) ) ) {
if ( (
filemtime( 'verify' . '/' . $captchaFile ) + 900 ) < time() ) {
unlink( 'verify' . '/' . $captchaFile );
}
}
}

closedir( $handle );

$handle = @fopen( 'verify' . '/' . $fileName, 'w' );

if ( !
$handle ) {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Access Code Validation Error: unable to create captcha control file. Script will quit
now.</body></html>';
exit;
}

fclose($handle);

if (
imagetypes() & IMG_JPG) {
header('Content-type: image/jpeg');
imagejpeg($im);
} elseif (
imagetypes() & IMG_PNG) {
header('Content-type: image/png');
imagepng($im);
}
exit;

}

function
DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (
is_array($fieldValue) ) {
return
array_map('DoStripSlashes', $fieldValue);
} else {
return
trim(stripslashes($fieldValue));
}
} else {
return
$fieldValue;
}
}

function
FilterCChars($theString) {
return
preg_replace('/[\x00-\x1F]/', '', $theString);
}

function
ProcessTextField(&$codeHtmlForm, $fieldName, $fieldValue) {

$tagPattern = '/(<input[^>]+name=[\'\"]?\Q' . $fieldName . '\E[\'\"\s]+[^>]*>)/i';
preg_match($tagPattern, $codeHtmlForm, $matches);

$htmlTag = $matches[1];
$valuePattern = '/value=[\'\"]?[^\'\"]*[\'\"]+/i';
$replacementPattern = 'value="' . $fieldValue . '" ';

if (
preg_match($valuePattern, $htmlTag)) {
$htmlTagToReplace = preg_replace($valuePattern, $replacementPattern, $htmlTag);
} else {
$valuePattern = '/([^>\/]*)([\/]?>)/';
$replacementPattern = '\1 value="' . $fieldValue . '" \2';
$htmlTagToReplace = preg_replace($valuePattern, $replacementPattern, $htmlTag);
}

$codeHtmlForm = preg_replace($tagPattern, $htmlTagToReplace, $codeHtmlForm);

}

function
ProcessTextArea(&$codeHtmlForm, $fieldName, $fieldValue) {

$tagPattern = '/(<textarea[^>]+name=[\'\"]?\Q' . $fieldName . '\E[\'\"\s]+[^>]*)>(.*?)(<\/textarea>)/is';
$replacementPattern = '\1>' . $fieldValue . '\3';

$codeHtmlForm = preg_replace($tagPattern, $replacementPattern, $codeHtmlForm);

}

function
ProcessSelect(&$codeHtmlForm, $fieldName, $fieldValues) {

# Search the select tag
$selectPattern = '/(<select[^>]+name=[\'\"]?\Q' . $fieldName . '\E(\[\]|)[\'\"\s]+[^>]*>.*?<\/select>)/is';
$numMatches = preg_match($selectPattern, $codeHtmlForm, $selectMatches);

$originalSelectTag = $selectMatches[1];

# Remove the selected option tags
$selectedPattern = '/(<option[^>]+)([\s]+selected="selected"|[\s]+selected)([^>]*)>/i';
$replacementPattern = '\1\3>';
$modifiedSelectTag = preg_replace($selectedPattern, $replacementPattern, $originalSelectTag);

# Find the tags that must be checked
if (!is_array($fieldValues)) {
if (
strlen($fieldValues) > 0) {
$fieldValues = array($fieldValues);
} else {
return;
}
}

foreach (
$fieldValues as $fieldValue) {
# Find the options that must be selected
$optionPattern = '/(<option[^>]+value=[\'\"]?\Q' . $fieldValue . '\E[\'\"\s]+[^>]*)(>)/i';
$replacementPattern = '\1 selected="selected"\2';
$modifiedSelectTag = preg_replace($optionPattern, $replacementPattern, $modifiedSelectTag);
}

# Replace the code in the form
$codeHtmlForm = preg_replace($selectPattern, $modifiedSelectTag, $codeHtmlForm);

}


function
ProcessPHPFile($PHPFile) {

ob_start();

if (
file_exists($PHPFile)) {
require
$PHPFile;
} else {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Forms To Go - Error: Unable to load HTML form: ' . $PHPFile . '</body></html>';
exit;
}

return
ob_get_clean();
}

function
CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars,
$optional) {

$regEx = '';

if (
$limitAlpha == kYes) {
$regExp = 'A-Za-z';
}

if (
$limitNumbers == kYes) {
$regExp .= '0-9';
}

if (
$limitEmptySpaces == kYes) {
$regExp .= ' ';
}

if (
strlen($limitExtraChars) > 0) {

$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|', '/');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|', '\/');

$regExp .= str_replace($search, $replace, $limitExtraChars);

}

if ( (
strlen($regExp) > 0) && (strlen($value) > 0) ){
if (
preg_match('/[^' . $regExp . ']/', $value)) {
return
false;
}
}

if ( (
strlen($value) == 0) && ($optional === kOptional) ) {
return
true;
} elseif ( (
strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return
true;
} elseif ( (
strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return
true;
} elseif ( (
strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return
true;
} else {
return
false;
}

}


function
CheckEmail($email, $optional) {
if ( (
strlen($email) == 0) && ($optional === kOptional) ) {
return
true;
} elseif (
preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i",
$email) == 1 ) {
return
true;
} else {
return
false;
}
}


function
CheckEqualTo($original, $repeated) {
if (
$original == $repeated) {
return
true;
} else {
return
false;
}
}


function
CheckFTGCaptcha($accessCode) {

$captchaDir = 'verify';

if ( !
is_dir( $captchaDir ) ) {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Access Code Validation Error: directory &quot;verify&quot; not found. Script will
quit now.</body></html>';
exit;
}

$handle = opendir( $captchaDir );

$fileAccessCode = substr( md5( $accessCode ), 0, 12 );

while (
$captchaFile = readdir( $handle ) ) {
if (
substr( $captchaFile, 0, 1 ) != '.' ) {
if (
$fileAccessCode == $captchaFile ) {
return
true;
}
}
}
return
false;
}

function
DeleteCaptcha($accessCode) {

$captchaDir = 'verify';

if ( !
is_dir( $captchaDir ) ) {
echo
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"
/><title>Error</title></head><body>Access Code Validation Error: directory &quot;verify&quot; not found. Script will
quit now.</body></html>';
exit;
}

$handle = opendir( $captchaDir );

$fileAccessCode = substr( md5( $accessCode ), 0, 12 );

while (
$captchaFile = readdir( $handle ) ) {
if ( (
substr( $captchaFile, 0, 1 ) != '.' ) && ( substr( $captchaFile, 0, 1 ) != '_' ) && ( !is_dir( 'verify' . '/' .
$captchaFile ) ) ) {
if (
$fileAccessCode == $captchaFile ) {
unlink( 'verify' . '/' . $captchaFile );
return;
}
}
}

}



if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

if ( isset(
$_GET['formstogoimgflt']) ) {
CaptchaGenerator();
exit;
}

$FTGreason = DoStripSlashes( $_POST['reason'] );
$FTGfirst_name = DoStripSlashes( $_POST['first_name'] );
$FTGlast_name = DoStripSlashes( $_POST['last_name'] );
$FTGemail = DoStripSlashes( $_POST['email'] );
$FTGemail2 = DoStripSlashes( $_POST['email2'] );
$FTGmessage = DoStripSlashes( $_POST['message'] );
$FTGverify = DoStripSlashes( $_POST['verify'] );



$validationFailed = false;

# Fields Validations


if (!CheckString($FTGreason, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['reason'] = 'Tell us why you\'re contacting us so we can route your message correctly.';
$validationFailed = true;
}

if (!
CheckString($FTGfirst_name, 1, 36, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['first_name'] = 'Please enter your First Name';
$validationFailed = true;
}

if (!
CheckString($FTGlast_name, 1, 36, kStringRangeBetween, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['last_name'] = 'Please enter your Last Name';
$validationFailed = true;
}

if (!
CheckEmail($FTGemail, kMandatory)) {
$FTGErrorMessage['email'] = 'You\'ll need to enter your e-mail address before you can send this.';
$validationFailed = true;
}

if (!
CheckEqualTo($FTGemail2, $FTGemail)) {
$FTGErrorMessage['email2'] = 'Your E-mail addresses don\'t match.';
$validationFailed = true;
}

if (!
CheckFTGCaptcha($FTGverify)) {
$FTGErrorMessage['verify'] = 'Your input didn\'t match the (CASE SENSITIVE) characters displayed, please try again.';
$validationFailed = true;
}



# Display HTML form with filled values

if ($validationFailed === true) {

$fileHtmlForm = 'http://your_domain.com/your_contact_form.php';

$codeHtmlForm = file_get_contents($fileHtmlForm);


ProcessSelect($codeHtmlForm, 'reason', $FTGreason);
ProcessTextField($codeHtmlForm, 'first_name', $FTGfirst_name);
ProcessTextField($codeHtmlForm, 'last_name', $FTGlast_name);
ProcessTextField($codeHtmlForm, 'email', $FTGemail);
ProcessTextField($codeHtmlForm, 'email2', $FTGemail2);
ProcessTextArea($codeHtmlForm, 'message', $FTGmessage);


$errorList = @implode("\n", $FTGErrorMessage);
$codeHtmlForm = str_replace('<!--VALIDATIONERROR-->', $errorList, $codeHtmlForm);

$codeHtmlForm = str_replace('<!--FIELDVALUE:reason-->', $FTGreason, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:first_name-->', $FTGfirst_name, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:last_name-->', $FTGlast_name, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:email2-->', $FTGemail2, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:message-->', $FTGmessage, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:verify-->', $FTGverify, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:reason-->', $FTGErrorMessage['reason'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:first_name-->', $FTGErrorMessage['first_name'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:last_name-->', $FTGErrorMessage['last_name'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:email-->', $FTGErrorMessage['email'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:email2-->', $FTGErrorMessage['email2'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:verify-->', $FTGErrorMessage['verify'], $codeHtmlForm);
echo
$codeHtmlForm;
}
if (
$validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("$FTGreason");
$emailBody = "You've received a message submitted via the\n"
. "Organization Help Desk\n"
. "\n"
. "The person submitting this information is: $FTGfirst_name $FTGlast_name\n"
. "\n"
. "The message was sent from: $FTGemail\n"
. "\n"
. "\n"
. "Here's what it said:\n"
. "$FTGmessage\n"
. "\n"
. "This message was sent from IP address: $clientIP on " . date('m/d/y') . " at " . date('h:i:s A') . "\n"
. "\n"
. "";





foreach (
$accountsRecords as $record): //Populate mail destination for each position or committee (the $$ is not a typo,
it creates a variable using the name stored in $position_email).
if ((
$record['board_of_director_position_1'] && $record['board_of_director_position_1_email'] == 1 ) &&
$record['board_of_director_position_1:label'] == $FTGreason) {
$position_1_email = strtolower($record['email']); // format the position
$position_1_email = preg_replace('/\s+/', '_', $position_1_email );
$position_1_email = preg_replace('/-/', '_', $position_1_email );
$output1 .= $position_1_email. ',' ;
} ;
if ((
$record['board_of_director_position_2'] && $record['board_of_director_position_2_email'] == 1 ) &&
$record['board_of_director_position_2:label'] == $FTGreason ) {
$position_2_email = strtolower($record['email']); // format the position
$position_2_email = preg_replace('/\s+/', '_', $position_2_email );
$position_2_email = preg_replace('/-/', '_', $position_2_email );
$output2 .= $position_2_email. ',' ;
} ;
if ((
$record['board_of_director_position_3'] && $record['board_of_director_position_3_email'] == 1 &&
$record['board_of_director_position_1:label'] == $FTGreason)) {
$position_3_email = strtolower($record['email']); // format the position
$position_3_email = preg_replace('/\s+/', '_', $position_3_email );
$position_3_email = preg_replace('/-/', '_', $position_3_email );
$output3 .= $position_3_email. ',' ;
} ;
endforeach ;
$emailTo = $output1.$output2.$output3 ;
$emailTo = rtrim($emailTo,','); // remove trailing comma
$emailback = $common_informationRecord['board_backup_email']; // "common_information" is a single record editor
if ($emailTo == ''){$emailTo = $emailback ;};
$emailFrom = FilterCChars("$FTGemail");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"UTF-8\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
$confEmailTo = FilterCChars($FTGemail); // Confirmation Email to User
$confEmailSubject = FilterCChars("Your Message To The Organization");
$confEmailBody = chunk_split( base64_encode( "Hello $FTGfirst_name $FTGlast_name,\n"
. "\n"
. "Thanks for caring enough to contact us.\n"
. "\n"
. "You sent a message to the $FTGreason\n"
. "\n"
. "You sent your message from: $FTGemail\n"
. "\n"
. "Here is what it said:\n"
. "$FTGmessage\n"
. "\n"
. "They've received your message and will get back to you shortly.\n"
. "\n"
. "Best,\n"
. "\n"
. "The Organzation\n"
. "\n"
. "" ) );
$confEmailHeader = "From: no-reply@your_domain.com\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"UTF-8\"\n"
. "Content-transfer-encoding: base64\n";
mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);
DeleteCaptcha($FTGverify);
# Redirect user to success page
header("Location: http://www.your_domain.com/contactsuccess.php");
}
?>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service