Please try again.';
$post_mail = FALSE;
}
}
if ($post_mail === TRUE) {
// setup arrays
$fields = array();
$fields_keys = array();
$send_values = array();
// get the fields array
$fields = $_POST['fields'];
// get the field_keys array
$fields_keys = array_keys($fields);
// check the required field list
// start counting
$counter = 0;
//setup the field name and field value array;
foreach($fields_keys as $key_value) {
$check_values[$counter][value] = $fields[$key_value];
$key_value = str_replace("_", " ", $key_value); // replace underscore with spaces
$key_value = ucwords($key_value); // Set proper case
$check_values[$counter][field] = $key_value;
$counter++;
}
//print_r ($check_values);
//exit();
foreach($check_values as $check_field) {
$field = $check_field[field];
$value = $check_field[value];
$asterix = strpos($field , "Req");
if ($asterix != FALSE and empty($value)) {
$field = str_replace("Req", "", $field);
$message = "The " . $field . " field is missing or empty. Please try again.";
$post_mail = FALSE;
break;
}
}
}
if ($post_mail === TRUE) {
$from_email = '';
$from_name = '';
$from_surname = '';
// start counting
$counter = 0;
//setup the field name and field value array;
foreach($fields_keys as $key_value) {
if (array_search($key_value, $ignore_list) !== FALSE){
if (array_search($key_value, $con_list['alert']) !== FALSE) {
$code_key = array_search($key_value, $con_list['alert']);
eval($con_list['code'][$code_key]);
$counter++;
continue;
}
continue;
}
$send_values[value][] = $fields[$key_value];
$key_value = str_replace("_", " ", $key_value); // replace underscore with spaces
$key_value = str_replace("_req", "", $key_value); // replace required asterix
$key_value = ucwords($key_value); // Set proper case
$send_values[field][] = $key_value;
$counter++;
}
// this is done as php arrays start at 0 by default.
$field_count = $counter - 1;
// set up data spacing based on max field length
$max_space = 0;
foreach($send_values[field] as $field_name) {
$len = strlen($field_name);
if ($len > $max_space) {
$max_space = $len;
}
}
$max_space = $max_space + 4;
// set up data body
//echo $send_values[field][$i].'
';
//echo $send_values[value][$i].'
';
for ($i = 0; $i <= $field_count; $i++) {
if (strtoupper(substr($send_values[field][$i],0,5)) == "EMAIL" and empty($from_email)) {
$from_email = $send_values[value][$i];
}
if (strtoupper(substr($send_values[field][$i],0,4)) == "FIRST_NAME" and empty($from_name)) {
$from_name = $send_values[value][$i];
}
if (strtoupper(substr($send_values[field][$i],0,4)) == "NAME" and empty($from_name)) {
$from_name = $send_values[value][$i];
}
if (strtoupper(substr($send_values[field][$i],0,7)) == "SURNAME" and empty($from_surname)) {
$from_surname = $send_values[value][$i];
};
$field_output = str_pad($send_values[field][$i], $max_space);
$value_output = $send_values[value][$i];
$line_output = $field_output . $value_output . $lf;
$data_body .= $line_output;
}
$mail_body = $data_body . $lf;
$mail_header = 'This email was sent via secure form to email'.$lf;
//$mail_header .= '-----Original Message-----'.$lf;
//$mail_header .= 'From: '.$from_email. ' [mailto:'.$from_email.']'.$lf;
//$mail_header .= 'To: '.$to_email.$lf;
//if (!empty($cc_email)) {
// $mail_header .= 'CC: '.$cc_email.$lf;
//}
//if (!empty($bcc_email)) {
// $mail_header .= 'BCC: '.$bcc_email.$lf;
//}
//$mail_header .= 'Subject: '.$website_name.' Contact Enquiry'.$lf;
//$mail_header .= 'Reply-To: '.$from_email.$lf;
//$mail_header .= $lf.$lf;
$mail_footer = '';
$mail_footer .= 'The above enquiry was received from '.$from_name .' '.$from_surname .' <'.$from_email .'>, from our '.$website_name.' website.'.$lf;
$mail_footer .= $lf;
$mail_footer .= $mail_signature;
$mail_text = $mail_header . $mail_body . $mail_footer;
$to = $to_email;
$from = $from_email;
$subject = $website_name.' Contact Enquiry';
$body = $mail_text;
$cc = $cc_email;
$bcc = $bcc_email;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/plain; charset=\"iso-8859-1\"' . "\r\n";
// Additional headers
//$headers .= 'To: '. $to_email . $lf;
$headers .= 'From: '. $from_email . $lf;
//$headers .= 'Cc: ' . $cc_email . $lf;
$headers .= 'Bcc: ' . $bcc_email .$lf;
// Mail it
$mailed = mail($to, $subject, $body, $headers);
if ($mailed === TRUE) {
$submit_js = '
';
//$message = "Thank you for your interest. We will contact you shortly.";
}else {
$message = "An error has occured.
Please try again.";
}
}
if (!empty($submit_js)) {
echo $submit_js;
}
?>
Contact Us @ Peace Valley Guest House, Napier, Overberg, Wester Cape