php email help

Ok Folks I am beginning to go slowly insane with this code! I am trying to rework some code for a PHP email form that a previous person had created. I am trying to do 2 different things one thing is I am trying to add HTML formatting into the email that is generated, I have tried putting the HTML headers in but no matter where I put the tags it still just prints the tags instead of for example bolding the section I am specifying. The second thing is I am trying to fix it so that when the email is generated it omits the empty fields. Thank you in advance for any assistance you can provide

[php]<?php
$problems = array();
$showform = 0;
$errorMessage = “”;

	function validate($field, $value) {
	
		// || $field == "id" || $field == "phone" || $field == "course" || $field == "instructor"
	
		/*if ($field == "name" || $field == "email" || $field == "computers" || $field == "info") {*/
			if ($value == "") {
				return 0;
			} else {
				return 1;
			}
		/*}*/
		
		/*if ($field == "system" || $field == "browser" || $field == "issue" || $field == "multiple") {
			if ($value == "----" || $value == "") {
				return 0;
			} else {
				return 1;
			}
		}*/
	
	}

	if($_POST) {
	
		//'id','phone','course','instructor',
	
		$fields = array('name','title', 'date', 'time', 'building', 'room', 'location', 'person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');
		$x = 0 - 1;
		
		foreach($fields as $field) {
		
			if(isset($_POST[$field])) {
				$validation = validate($field, $_POST[$field]);
				if ($validation == 1) {
					$x++;	
					$info[$x] = $_POST[$field];
				} else {
					$problems[$field] = 1;
					$showform = 1;
				}
			} else {
				$problems[$field] = 1;
				$showform = 1;
			}
		}
	
	} else {
		$showform = 1;
	}
	
	if(count($problems) < 1 && $_POST) {
	
		// DO THE MAILING HERE

		$fields = array('title', 'name','date', 'time', 'building', 'room', 'location', 'title1','person',  'phone1', 'title2', 'person2', 'phone2','title3','person3',  'phone3','title4','person4',  'phone4', 'type1', 'type2', 'type3', 'type4', 'type5', 'type6', 'type7', 'type8', 'type9', 'explanation', 'security', 'police', 'witness','wtitle1', 'wperson',  'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3',  'wphone3', 'acttaken', 'followact');
		
		$to = "[email protected]";
		$to2 = "[email protected]";
		$subject = "Incident / Unusual Occurrence Report";
		$headers='MIME-Version: 1.0' .PHP_EOL;
    	$headers .='Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
		$headers = "From: [email protected]\r\n" . "X-Mailer: php";
		$greet = "The following was submitted on " . date("F j, Y, g:i a") . "\n\n";
		
		$body =   $greet  ; 
		$cn = 1;

		
		foreach($fields as $efield) {
		
			
			if(isset($_POST[$efield])) {
			
				if($efield == "type1" || $efield == "type2" || $efield == "type3" || $efield == "type4" || $efield == "type5" || $efield == "type6" || $efield == "type7" || $efield == "type8" || $efield == "type9" ) {
					$body.= "<strong>Type of Occurrence:</strong>" . $_POST[$efield] . "\n\n";
					$cn++;
				} elseif($efield == "title") {
					$body.= "Name of Person Filing Report: " . $_POST[$efield] . " ";

				} elseif($efield == "name") {
					$body.= "   " . $_POST[$efield] . "\n________________________________________\n\n";
				
				} elseif($efield == "date") {
					$body.= "Date of Occurrence: " . $_POST[$efield] . "  \t  ";
				} elseif ($efield == "time") {
					$body.= "Time: " . $_POST[$efield] . "\n________________________________________\n\n";
				} elseif ($efield == "building") {
					$body.= "Building: " . $_POST[$efield] . "   \t\t  ";
				} elseif ($efield == "room") {
					$body.= "Room: " . $_POST[$efield] . "\n\n";
					} elseif ($efield == "location") {
					$body.= "Description of Location: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";
				} elseif ($efield == "title1") {
					$body.= "First Person involved: " . $_POST[$efield] . " ";
				} elseif ($efield == "person") {
					$body.= " \t" . $_POST[$efield] . "\n";
								
				

				} elseif ($efield == "phone1") {
					$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";

}elseif ($efield == “title2”) {
$body.= "Second Person involved: " . $_POST[$efield] . " ";
} elseif ($efield == “person2”) {
$body.= " " . $_POST[$efield] . “\n”;

				 } elseif ($efield == "phone2") {
					$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";

} elseif ($efield == “title3”) {
$body.= "Third Person involved: " . $_POST[$efield] . " ";
} elseif ($efield == “person3”) {
$body.= " " . $_POST[$efield] . “\n”;

				} elseif ($efield == "phone3") {
					$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
			
				} elseif ($efield == "title4") {
					$body.= "Fourth Person Involved: " . $_POST[$efield] . "  ";
				} elseif ($efield == "person4") {
					$body.= " " . $_POST[$efield] . " \n";
			
				
			

				} elseif ($efield == "phone4") {
					$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
				
				} elseif ($efield == "explanation") {
					$body.= "Detailed Explanation: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";
				} elseif ($efield == "security") {
					$body.= "Security called: " . $_POST[$efield] . "\n\n";
				} elseif ($efield == "police") {
					$body.= "Police called: " . $_POST[$efield] . "\n\n";
				} elseif ($efield == "witness") {
					$body.= "Were there witnesses: " . $_POST[$efield] . "\n________________________________________\n\n";



			} elseif($efield == "wtitle1") {
					$body.= "Witness: " . $_POST[$efield] . " ";

			
			} elseif ($efield == "wperson") {
					$body.= " \t" . $_POST[$efield] . "\n";
								
				

				} elseif ($efield == "wphone1") {
					$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";

}elseif ($efield == “wtitle2”) {
$body.= "Second witness: " . $_POST[$efield] . " ";
} elseif ($efield == “wperson2”) {
$body.= " " . $_POST[$efield] . “\n”;

				 } elseif ($efield == "wphone2") {
					$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";

} elseif ($efield == “wtitle3”) {
$body.= "Third witness: " . $_POST[$efield] . " ";
} elseif ($efield == “wperson3”) {
$body.= " " . $_POST[$efield] . “\n”;

				} elseif ($efield == "wphone3") {
					$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
			

				} elseif ($efield == "acttaken") {
					$body.= "Immediate Action Taken: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";
				} elseif ($efield == "followact") {
					$body.= "What Follow-up Action will be taken: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";

}
}
}

		mail($to, $subject, $body, $headers);
		mail($to2, $subject, $body, $headers);
		
		?>
		<p class="style1">Your report has been submitted.<br><br></p>
		<?php
	
	}
	
	if($showform == 1) {
?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service