Page 1 of 1

Email Form Message Body Empty - New Server

Posted: Thu Jan 10, 2013 12:30 pm
by markformac
After being with GoDaddy for years, I switched to Rackspace.com to use a virtual cloud server. I re-uploaded the exact same website that was on GoDaddy. While everything appeared ok, my web forms are not working properly. They appear to function as they should on the website, but when I receive the emails, the message body is empty.

Here are the contact form URLs:

http://cop-apps.net/aboutme/contact/index.php
http://cop-apps.net/mobile/contact.php
http://cop-apps.net/android/contact.php
http://cop-apps.net/apple/contact.php

I'm not thinking it is anything related to the page because it functioned correctly. I'm thinking it is on server side. GoDaddy preinstalls the below software. Can anyone advise if any of the uninstalled software could likely be the issue?

Apache 2.0 (installed on new server)
PHP 4.3 (installed on new server)
MySQL 3.23 (installed on new server)
PostgreSQL 7.4
phpMyAdmin (installed on new server)
phpPgAdmin 4.0
Tomcat 5.5
SpamAssassin 3.0
SquirrelMail 1.4 (I use Exchange Online for my email service provider)
Webalizer 2.0

Just to provide a thorough posting addressing all possible issues, below is the code from one of the .php pages:

From http://cop-apps.net/apple/contact.php

Code: Select all

<div class="message-text"><?php echo $_SESSION['formMessage']; unset($_SESSION['formMessage']); ?></div><br />

<form action="./files/mailer.php" method="post" enctype="multipart/form-data">
	 <div>
		<label>Your Name:</label> *<br />
		<input class="form-input-field" type="text" value="<?php echo check('element0'); ?>" name="form[element0]" size="40"/><br /><br />

		<label>Your Email:</label> *<br />
		<input class="form-input-field" type="text" value="<?php echo check('element1'); ?>" name="form[element1]" size="40"/><br /><br />

		<label>Product:</label> *<br />
		<select name="form[element2]">			<option <?php echo check('element2', 'select','Please Select...'); ?> value="Please Select...">Please Select...</option>
			<option <?php echo check('element2', 'select','AllLaw'); ?> value="AllLaw">AllLaw</option>
			<option <?php echo check('element2', 'select','CopCal'); ?> value="CopCal">CopCal</option>
			<option <?php echo check('element2', 'select','ER Locator'); ?> value="ER Locator">ER Locator</option>
			<option <?php echo check('element2', 'select','EvidenceCam'); ?> value="EvidenceCam">EvidenceCam</option>
			<option <?php echo check('element2', 'select','FBI for LEOs'); ?> value="FBI for LEOs">FBI for LEOs</option>
			<option <?php echo check('element2', 'select','FI-Pad'); ?> value="FI-Pad">FI-Pad</option>
			<option <?php echo check('element2', 'select','GPS Coordinates'); ?> value="GPS Coordinates">GPS Coordinates</option>
			<option <?php echo check('element2', 'select','Ohio Cop'); ?> value="Ohio Cop">Ohio Cop</option>
			<option <?php echo check('element2', 'select','Photo Evidence'); ?> value="Photo Evidence">Photo Evidence</option>
			<option <?php echo check('element2', 'select','US Cop'); ?> value="US Cop">US Cop</option>
			<option <?php echo check('element2', 'select','Other...'); ?> value="Other...">Other...</option>
		</select><br /><br />

		<label>Subject:</label> *<br />
		<input class="form-input-field" type="text" value="<?php echo check('element3'); ?>" name="form[element3]" size="40"/><br /><br />

		<label>iOS Device:</label> *<br />
		<select name="form[element4]">			<option <?php echo check('element4', 'select','Please Select&hellip;'); ?> value="Please Select&hellip;">Please Select&hellip;</option>
			<option <?php echo check('element4', 'select','iPad 3'); ?> value="iPad 3">iPad 3</option>
			<option <?php echo check('element4', 'select','iPad 2'); ?> value="iPad 2">iPad 2</option>
			<option <?php echo check('element4', 'select','iPad (original)'); ?> value="iPad (original)">iPad (original)</option>
			<option <?php echo check('element4', 'select','iPhone 5'); ?> value="iPhone 5">iPhone 5</option>
			<option <?php echo check('element4', 'select','iPhone 4S'); ?> value="iPhone 4S">iPhone 4S</option>
			<option <?php echo check('element4', 'select','iPhone 4'); ?> value="iPhone 4">iPhone 4</option>
			<option <?php echo check('element4', 'select','iPhone 3GS'); ?> value="iPhone 3GS">iPhone 3GS</option>
			<option <?php echo check('element4', 'select','iPhone 3G'); ?> value="iPhone 3G">iPhone 3G</option>
		</select><br /><br />

		<label>iOS Version:</label> *<br />
		<select name="form[element5]">			<option <?php echo check('element5', 'select','Please Select...'); ?> value="Please Select...">Please Select...</option>
			<option <?php echo check('element5', 'select','6.1 (beta)'); ?> value="6.1 (beta)">6.1 (beta)</option>
			<option <?php echo check('element5', 'select','6.0.2'); ?> value="6.0.2">6.0.2</option>
			<option <?php echo check('element5', 'select','6.0.1'); ?> value="6.0.1">6.0.1</option>
			<option <?php echo check('element5', 'select','6.0'); ?> value="6.0">6.0</option>
			<option <?php echo check('element5', 'select','5.1.1'); ?> value="5.1.1">5.1.1</option>
			<option <?php echo check('element5', 'select','5.1'); ?> value="5.1">5.1</option>
			<option <?php echo check('element5', 'select','5.0.1'); ?> value="5.0.1">5.0.1</option>
			<option <?php echo check('element5', 'select','5.0'); ?> value="5.0">5.0</option>
			<option <?php echo check('element5', 'select','4.3.5'); ?> value="4.3.5">4.3.5</option>
			<option <?php echo check('element5', 'select','4.3.4'); ?> value="4.3.4">4.3.4</option>
			<option <?php echo check('element5', 'select','4.3.3'); ?> value="4.3.3">4.3.3</option>
			<option <?php echo check('element5', 'select','4.3.2'); ?> value="4.3.2">4.3.2</option>
			<option <?php echo check('element5', 'select','4.3.1'); ?> value="4.3.1">4.3.1</option>
			<option <?php echo check('element5', 'select','4.3.0'); ?> value="4.3.0">4.3.0</option>
			<option <?php echo check('element5', 'select','4.2.10'); ?> value="4.2.10">4.2.10</option>
			<option <?php echo check('element5', 'select','4.2.9'); ?> value="4.2.9">4.2.9</option>
			<option <?php echo check('element5', 'select','4.2.8'); ?> value="4.2.8">4.2.8</option>
			<option <?php echo check('element5', 'select','4.2.7'); ?> value="4.2.7">4.2.7</option>
			<option <?php echo check('element5', 'select','4.2.6'); ?> value="4.2.6">4.2.6</option>
			<option <?php echo check('element5', 'select','4.2.5'); ?> value="4.2.5">4.2.5</option>
			<option <?php echo check('element5', 'select','4.2.1'); ?> value="4.2.1">4.2.1</option>
			<option <?php echo check('element5', 'select','4.2'); ?> value="4.2">4.2</option>
			<option <?php echo check('element5', 'select','4.1'); ?> value="4.1">4.1</option>
			<option <?php echo check('element5', 'select','4.0.2'); ?> value="4.0.2">4.0.2</option>
			<option <?php echo check('element5', 'select','4.0.1'); ?> value="4.0.1">4.0.1</option>
			<option <?php echo check('element5', 'select','4.0'); ?> value="4.0">4.0</option>
			<option <?php echo check('element5', 'select','Other (specify below)'); ?> value="Other (specify below)">Other (specify below)</option>
		</select><br /><br />

		<label>Message:</label> *<br />
		<textarea class="form-input-field" name="form[element6]" rows="8" cols="38"><?php echo check('element6'); ?></textarea><br /><br />

		<div style="display: none;">
			<label>Spam Protection: Please don't fill this in:</label>
			<textarea name="comment" rows="1" cols="1"></textarea>
		</div>
		<input type="hidden" name="form_token" value="<?php echo $security_token; ?>" />
		<input class="form-input-button" type="reset" name="resetButton" value="Reset" />
		<input class="form-input-button" type="submit" name="submitButton" value="Submit" />
	</div>
</form>

<br />
<div class="form-footer"><?php echo $_SESSION['formFooter']; unset($_SESSION['formFooter']); ?></div><br />

<?php unset($_SESSION['form']); ?>
		</div>
From http://cop-apps.net/apple/files/mailer.php'

Code: Select all

<?php
//start the session
session_start();

//////////////////////////////////////////////////////
// Begin variables to be written out by RapidWeaver //
//////////////////////////////////////////////////////

//set the return URL
$return_url = "../contact.php";

//set the users email address
$email = "mark@cop-apps.net";

//array of fields in form. (In the format "field_name" => "field_label")
$form_fields = array(
"element0" => 'Your Name:',
"element1" => 'Your Email:',
"element2" => 'Product:',
"element3" => 'Subject:',
"element4" => 'iOS Device:',
"element5" => 'iOS Version:',
"element6" => 'Message:'
);

$required_fields = array("element0", "element1", "element2", "element3", "element4", "element5", "element6");

$mail_from_name 	= "element0";
$mail_from_email 	= "element1";
$mail_subject 		= "element3";

//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 = 'Your message has been sent, now get back to work!';
$message_unset_fields = "Fields marked with * are required.";

////////////////////////////////////////////////////
// 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 = "<html>\n<head>\n<title>" .
	safe_escape_string($subject) .
	"</title>\n</head>\n<body>\n<p>\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 .= '<b>' . safe_escape_string($label) . '</b> ';
		$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)) . "<br /><br />\n";
		$text_content .= "$string\n\n";
	}
	
	//close the HTML content.
	$html_content .= "</p>\n</body>\n</html>";
	
	/////////////////////////////
	// CONSTRUCT EMAIL MESSAGE //
	/////////////////////////////
	
	//Now we combine both HTML and plain text version of the email into one.
	//Creating the message body which contains a Plain text version and an HTML version,
	//users email client will decide which version to display
	$message = "\r\n--$mixed_mime_boundary\r\n" .
	"Content-Type: multipart/alternative; boundary=$alt_mime_boundary\r\n\r\n" .
	"--$alt_mime_boundary\r\n" .
	"Content-Type: text/plain; charset=UTF-8; format=flowed\r\n" .
	"Content-Transfer-Encoding: Quoted-printable\r\n\r\n" .
	"$text_content\r\n\r\n" .
	"--$alt_mime_boundary\r\n" .
	"Content-Type: text/html; charset=UTF-8\r\n" .
	"Content-Transfer-Encoding: Quoted-printable\r\n\r\n" .
	"$html_content\r\n\r\n" .
	"--$alt_mime_boundary--\r\n\r\n" .
	"\r\n\r\n--$mixed_mime_boundary";
	
	
	//////////////////////
	// FILE ATTACHMENTS //
	//////////////////////
	
	//loop through the $_FILES global array and add each attachment to the form.
	if (isset($_FILES)) {
		foreach ($_FILES as $attachment) {
			$filename = $attachment['name'];
			
			//if the file has been uploaded
			if ($attachment['error'] === UPLOAD_ERR_OK && is_uploaded_file($attachment['tmp_name'])) {
				$file = fopen($attachment['tmp_name'],'rb');
				$data = fread($file,filesize($attachment['tmp_name']));
				fclose($file);
				$data = chunk_split(base64_encode($data));
				
				$message .= "\r\nContent-Type: application/octet-stream; name=\"$filename\"" .
				"\r\nContent-Disposition: attachment; filename=\"$filename\"" .
				"\r\nContent-Transfer-Encoding: base64\r\n\r\n$data\r\n\r\n--$mixed_mime_boundary";
			} else if ($attachment['error'] !== UPLOAD_ERR_NO_FILE) {
				//try to provide a useful error message determined from the error code.
				switch ($attachment['error']) {
					case UPLOAD_ERR_INI_SIZE:
					case UPLOAD_ERR_FORM_SIZE:
						$error = "File $filename exceeds the " . ini_get('upload_max_filesize') . 'B limit for the server.';
						break;
					case UPLOAD_ERR_PARTIAL:
						$error = "Only part of the file $filename could be uploaded, please try again.";
						break;
					default:
						$error = "There has been an error attaching the file $filename, please try again.";
				}
				redirect($return_url, $error);
			}
		}
	}
	
	
	//finish off message
	$message .= '--';
	
	//for windows users.
	if ($windows_server === true) {
		ini_set('sendmail_from', $email);
	}
	
	//if the mail sending works
	if (@mail($email, $subject, $message, $headers)) {
		//set the success message
		$notice = $message_success;
		unset($_SESSION['form']);
	} else {
		$notice = "I'm sorry, there seems to have been an error trying to send your email. Please try again.";
	}
	
	//redirect to the form
	redirect($return_url, $notice);
}

//////////////////////
// GLOBAL FUNCTIONS //
//////////////////////

// Redirects back to the form, an optional session message can be defined.
function redirect($url, $message = NULL) {
	if ($message) {
		$_SESSION['formMessage'] = $message;
	}
	header('Location: ' . $url);
	exit;
}

// Function to escape data inputted from users. This is to protect against embedding
// of malicious code being inserted into the HTML email.
// Sample code: safe_escape_string($_POST['form_field'])
function safe_escape_string($string) {
	return htmlspecialchars($string, ENT_QUOTES);
}

// Function to check the validity of email address.
function check_email($email) {
	return (bool) preg_match('/^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}$/i', $email);
}

// Function to check the required fields are filled in.
function check_required_fields($required_fields) {
	foreach ($required_fields as $field) {
		if (( ! isset($_SESSION['form'][$field]) || empty($_SESSION['form'][$field])) &&
			( ! isset($_FILES[$field]) || empty($_FILES[$field]['name']))) {
			return false;
		}
	}
	return true;
}