"field_label")
$form_fields = array(
"element0" => 'Your Name:',
"element1" => 'Your Email:',
"element2" => 'Institution:',
"element3" => 'Sound Bite Title:',
"element4" => 'Vegetarian',
"element5" => ' '
);
$required_fields = array();
$mail_from_name = "element0";
$mail_from_email = "element1";
$mail_subject = "element5";
//uses the email address defined above as the from email.
$send_from_users_email = false;
//sets the PHP setting 'sendmail_from' for use on a windows server.
$windows_server = false;
// Set up the error and success messages.
$message_success = 'Thank you for Registering for MASM22
We look forward to seeing you at Hopkins';
$message_unset_fields = "";
////////////////////////////////////////////////////
// End variables to be written out by RapidWeaver //
////////////////////////////////////////////////////
// Check key variable from form against session key.
if ( ! isset($_POST['form_token']) || $_POST['form_token'] !== $_SESSION['security_token']) {
// Set a fixed error message if the keys don't match.
redirect($return_url, 'We cannot verify that you are trying to send an email from this form. Please try again.');
}
// SPAM checking. If the "comment" form field has been filled out,
// send back to form asking to remove content and exit the script.
if ($_POST['comment']) {
redirect($return_url, 'Please remove content from the last textarea before submitting the form again. This is to protect against SPAM abuse.');
}
/////////////////////////
// PROCESS FORM FIELDS //
/////////////////////////
$magic_quotes = (bool) get_magic_quotes_gpc();
foreach ($_POST['form'] as $key => $value) {
if ($magic_quotes) {
$value = stripslashes($value);
}
$_SESSION['form'][$key] = $value;
}
///////////////////////////
// CHECK REQUIRED FIELDS //
///////////////////////////
//if any of the required fields are empty
if (check_required_fields($required_fields) === false) {
//return to form with error message.
redirect($return_url, $message_unset_fields);
} else {
///////////////////////////////////
// ALL IS OK, SETUP GLOBAL VAR'S //
///////////////////////////////////
//check email address
if ( ! check_email($email)) unset($email);
//set mime boundry. Needed to send the email. Mixed seperates text from attachments.
$mixed_mime_boundary = 'rms-mix-x'.md5(mt_rand()).'x';
//alt seperates html from plain text.
$alt_mime_boundary = 'rms-alt-x'.md5(mt_rand()).'x';
//set the from address if user supplied email is invalid use form owners.
$submitted_email = '';
if (isset($_SESSION['form'][$mail_from_email])) {
$submitted_email = $_SESSION['form'][$mail_from_email];
}
if (check_email($submitted_email) && $send_from_users_email === false) {
$from = $reply_to = $_SESSION['form'][$mail_from_name].' <'.$submitted_email.'>';
} else {
$from = '<'.$email.'>';
$reply_to = check_email($submitted_email) ? '<'.$submitted_email.'>' : $from;
}
//set the email subject
$subject = '';
if (isset($_SESSION['form'][$mail_subject])) {
$subject = $_SESSION['form'][$mail_subject];
}
//email headers
if ($windows_server === true) {
$headers = "From: $from\r\n" .
"Reply-to: $reply_to\r\n" .
"MIME-Version: 1.0\r\nContent-Type: multipart/mixed; " .
"boundary=$mixed_mime_boundary";
} else {
$headers = "From: $from\n" .
"Reply-to: $reply_to\n" .
"MIME-Version: 1.0\nContent-Type: multipart/mixed; " .
"boundary=$mixed_mime_boundary";
}
////////////////////////////
// CONSTRUCT HTML CONTENT //
////////////////////////////
//Construct HTML email content, looping through each form element
//Note: When you get to a file attachment you need to use $_FILES['form_element']['name']
//This will just output the name of the file. The files will actually be attached at the end of the message.
//Set a variable for the message content
$html_content = "\n
\n";
////////////////////////////
// CONSTRUCT TEXT CONTENT //
////////////////////////////
//construct a plain text version of the email.
$text_content = '';
//build a message from the reply for both HTML and text in one loop.
foreach ($form_fields as $field => $label) {
$html_content .= '' . safe_escape_string($label) . ' ';
$text_content .= "$label ";
if (isset($_FILES[$field])) {
$string = (isset($_FILES[$field]['name'])) ? $_FILES[$field]['name'] : '';
} else {
$string = (isset($_SESSION['form'][$field])) ? $_SESSION['form'][$field] : '';
}
$html_content .= nl2br(safe_escape_string($string)) . "
\n";
$text_content .= "$string\n\n";
}
//close the HTML content.
$html_content .= "