Jump to content

PHP email form help


Inky1231

Recommended Posts

Ok I have two separate issues. The first is that I want to format the email so that the titles of the form areas are bolded (i.e., Name: Title:, etc...) the second issue is that I don't want the email to contain the blank fields (I.e. witness 2 etc.. if left empty)

any help is appreciated here is my code

  <p class="style2"><span class="style5"><strong>Incident / Unusual Occurrence Report</strong></span><br>
Danville Area Community College<br><br>
REPORT FORM</p>


<table width="481" height="657" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
   
   
    <td rowspan="2" valign="top" bgcolor="#FFFFFF" style="width: 481px"> 
<p align="center"class="style3"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
<?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 = "ampeck@earthlink.net";
		$to2 = "aabdelzaher@dacc.edu";
		$subject = "Incident / Unusual Occurrence Report";
		$headers = "From: noreply@dacc.edu\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.= "Type of Occurrence:" . $_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 if(count($problems) > 0) { ?>
	<p><strong><font color="red">PLEASE CORRECT ANY FIELDS WITH A RED * BY THEM</font></strong></p>
<?php } ?>

<form action="" method="post">
	<fieldset>
		<legend>
			<span lang="en-us">Incident Report</span>
		</legend>
					<div class="style6">
		<div class="style7">
		<br>
			<table style="width: 100%">
				<tr>
					<td style="width: 248px" class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="name">Name(s): <?php if(isset($problems['name'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="inputstyle" type="text" name="name" value="<?php if(isset($_POST['name'])){ print($_POST['name']); }?>" style=" width: 288px"></font></td>
					<td style="width: 148px" class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="title">Title: <?php if(isset($problems['title'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="style6" type="text" name="title" value="<?php if(isset($_POST['title'])){ print($_POST['title']); }?>" style=" width: 132px"></font></td>
								</tr>
							</table><p></p>
							<table >
								<tr>
									<td style="width: 132px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="date">Date of Occurrence: <?php if(isset($problems['date'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="inputstyle" type="text" name="date" value="<?php if(isset($_POST['date'])){ print($_POST['date']); }?>" style=" width: 118px"></font></td>
								<td style="width: 170px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="time">Time of Occurrence: <?php if(isset($problems['time'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="inputstyle" type="text" name="time" value="<?php if(isset($_POST['time'])){ print($_POST['time']); }?>" style=" width: 88px"></font></td>
		<td style="width: 111px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
<label class="formtext" for="building">Building: <?php if(isset($problems['building'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="inputstyle" type="text" name="building" value="<?php if(isset($_POST['building'])){ print($_POST['building']); }?>" style=" width: 110px"></font></td>

<td style="width:100px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="room">Room: <?php if(isset($problems['room'])) {?><font color="red">*</font><?php } ?></label><br>
		<input class="inputstyle" type="text" name="room" value="<?php if(isset($_POST['room'])){ print($_POST['room']); }?>" style=" width: 60px"></font></td>

								</tr>
							</table>
								<table style="width: 100%; height: 72px;">
									<tr>
										<td class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="location">Location Description: <?php if(isset($problems['location'])) {?><font color="red">*</font><?php } ?></label><br>
		<textarea name="location"  style=" width: 383px; height: 115px;" ></textarea></font><br></td>
									</tr>
								</table>
							<br>
		<p class="style5">Person (s) involved in 
								incident</p>
								<table >
									<tr>
										<td style="width: 200px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">

								<span lang="en-us">

		<label class="formtext" for="person">Name:<?php if(isset($problems['person'])) {?><font color="red">*</font><?php } ?></label></span><br>
		<input class="inputstyle" type="text" name="person" value="<?php if(isset($_POST['person'])){ print($_POST['person']); }?>" style="width: 249px"></font></td>
										<td style="width: 114px"><label class="formtext" for="title1">
										<span lang="en-us">Title</span>:</label><br>
										<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<input class="inputstyle" type="text" name="title1" value="<?php if(isset($_POST['title1'])){ print($_POST['title1']); }?>" style=" width: 100px"></font></td>
										<td style="width: 104px"><label class="formtext" for="phone1">
										<span lang="en-us">Phone</span>:</label><br>
		<input class="inputstyle" type="text" name="phone1" value="<?php if(isset($_POST['phone1'])){ print($_POST['phone1']); }?>" style="width: 75px"></td>
								</tr>
								<tr>
									<td style="width: 224px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<input type="text" name="person2" value="<?php if(isset($_POST['person2'])){ print($_POST['person2']); }?>" style="width: 249px" style="width: 249px"></font></td>
									<td style="width: 114px">
		<input class="inputstyle" type="text" name="title2" value="<?php if(isset($_POST['title2'])){ print($_POST['title2']); }?>" style="width: 100px"></td>
											<td style="width: 104px">
											<input class="inputstyle" type="text" name="phone2" value="<?php if(isset($_POST['phone3'])){ print($_POST['phone3']); }?>" style="width: 75px"></td></tr>

								<tr>
									<td style="width: 224px; height: 26px;"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
			<input class="inputstyle" type="text" name="person3" value="<?php if(isset($_POST['person3'])){ print($_POST['person3']); }?>" style="width: 252px"></font></td>
									<td style="width: 114px; height: 26px;">
		<input class="inputstyle" type="text" name="title3" value="<?php if(isset($_POST['title3'])){ print($_POST['title3']); }?>" style=" width: 100px"></td>
									<td style="width: 104px">
											<input class="inputstyle" type="text" name="phone3" value="<?php if(isset($_POST['phone3'])){ print($_POST['phone3']); }?>" style=" width: 75px"></td></tr>


								<tr>
									<td style="width: 224px">
									<input class="inputstyle" type="text" name="person4" value="<?php if(isset($_POST['person4'])){ print($_POST['person4']); }?>" style=" width: 252px"></td>
										<td style="width: 114px; height: 26px;">
		<input class="inputstyle" type="text" name="title4" value="<?php if(isset($_POST['title4'])){ print($_POST['title4']); }?>" style=" width: 100px"></td>
								<td style="width: 104px">
											<input class="inputstyle" type="text" name="phone4" value="<?php if(isset($_POST['phone4'])){ print($_POST['phone4']); }?>" style=" width: 75px"></td></tr>


							</table><fieldset>
		<legend>
			Please Select at least one:
		</legend>
<p class="style5">Type of Alleged Occurrence:</p>
							<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
							<table style="width: 100%">
								<tr>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type1" value="Disgruntled Action"><label class="formtext" for="type1">Disgruntled Action</label><br></td>
									<td style="width: 33%; height: 57px;">	<input class="inputstyle" type="checkbox" name="type2" value="Obscene Language"><label class="formtext" for="type2">Obscene Language</label><br></td>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type3" value="Verbal Threats"><label class="formtext" for="type3">Verbal Threats</label><br></td>
								</tr>
								<tr>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type4" value="Physical Threats"><label class="formtext" for="type4">Physical Threats<br></label><br></td>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type5" value="Inappropriate Physical Behavior"><label class="formtext" for="type5">Inappropriate Physical 
									<span lang="en-us">    
									</span>Behavior</label><br></td>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type6" value="Written Threat"><label class="formtext" for="type6">Written Threat<br></label></td>
								</tr>
								<tr>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type7" value="Sexual Offense"><label class="formtext" for="type7">Sexual Offense<br></label></td>
									<td style="width: 33%; height: 57px;"><input class="inputstyle" type="checkbox" name="type8" value="Robbery or Other Crime"><label class="formtext" for="type8">Robbery or Other 
									<span lang="en-us"> <br>    
									</span>Crimes</label><br></td>
									<td style="width: 33%; height: 57px;" class="style6"><input class="inputstyle" type="checkbox" name="type9" value="Other"><label class="formtext" for="type9">Other</label><br>
									<br>
								</td></div>
								</tr>
						</table><p></p>

</font><table style="width: 100%; height: 72px;">
									<tr>
										<td class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="explanation">Detailed Explanation: <?php if(isset($problems['explanation'])) {?><font color="red">*</font><?php } ?></label><br>
		<textarea name="explanation"  style=" width: 450px; height: 220px;" ></textarea></font><br></td>
									</tr>
								</table>

	   


							</fieldset><br><br>	<br>
							<fieldset>
		<legend>
			Actions Taken:
		</legend>
<div class="style7">
		<br>
		<label class="formtext" for="security"><?php if(isset($problems['security'])) {?><font color="red">*</font><?php } ?>Was Security Notified:</label>
						<select name="security" class="dropdownstyle">
							<option value="">--Choose one--</option>
							<option value="Yes">Yes</option>
							<option value="No">No</option></select><br><br>

							<label class="formtext" for="police"><?php if(isset($problems['police'])) {?><font color="red">*</font><?php } ?>Were Police Notified:</label>
						<select name="police" class="dropdownstyle">
							<option value="">--Choose one--</option>
							<option value="Yes">Yes</option>
							<option value="No">No</option></select><br><br>


							<label class="formtext" for="witness"><?php if(isset($problems['witness'])) {?><font color="red">*</font><?php } ?>Were there Witnesses?<br> (if yes, list names of witnesses):<span lang="en-us">
		</span></label>
						 <select name="witness" class="dropdownstyle">
							<option value="">--Choose one--</option>
							<option value="Yes">Yes</option>
							<option value="No">No</option></select><br>



		<p class="style5">Witnesses to the Incident:</p>
								<table >
									<tr>
										<td style="width: 200px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">

								<span lang="en-us">

		<label class="formtext" for="wperson">Name:</label></span><br>
		<input class="inputstyle" type="text" name="wperson" value="<?php if(isset($_POST['wperson'])){ print($_POST['wperson']); }?>" style="width: 249px"></font></td>
										<td style="width: 114px"><label class="formtext" for="wtitle1">
										<span lang="en-us">Title</span>:</label><br>
										<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<input class="inputstyle" type="text" name="wtitle1" value="<?php if(isset($_POST['wtitle1'])){ print($_POST['wtitle1']); }?>" style=" width: 100px"></font></td>
										<td style="width: 104px"><label class="formtext" for="wphone1">
										<span lang="en-us">Phone</span>:</label><br>
		<input class="inputstyle" type="text" name="wphone1" value="<?php if(isset($_POST['wphone1'])){ print($_POST['wphone1']); }?>" style="width: 75px"></td>
								</tr>
								<tr>
									<td style="width: 224px"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<input type="text" name="wperson2" value="<?php if(isset($_POST['wperson2'])){ print($_POST['wperson2']); }?>" style="width: 249px; width : 249px"></font></td>
									<td style="width: 114px">
		<input class="inputstyle" type="text" name="wtitle2" value="<?php if(isset($_POST['wtitle2'])){ print($_POST['wtitle2']); }?>" style="width: 100px"></td>
											<td style="width: 104px">
											<input class="inputstyle" type="text" name="wphone2" value="<?php if(isset($_POST['wphone3'])){ print($_POST['wphone3']); }?>" style="width: 75px"></td></tr>

								<tr>
									<td style="width: 224px; height: 26px;"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
			<input class="inputstyle" type="text" name="wperson3" value="<?php if(isset($_POST['wperson3'])){ print($_POST['wperson3']); }?>" style="width: 252px"></font></td>
									<td style="width: 114px; height: 26px;">
		<input class="inputstyle" type="text" name="wtitle3" value="<?php if(isset($_POST['wtitle3'])){ print($_POST['wtitle3']); }?>" style=" width: 100px"></td>
									<td style="width: 104px">
											<input class="inputstyle" type="text" name="wphone3" value="<?php if(isset($_POST['wphone3'])){ print($_POST['wphone3']); }?>" style=" width: 75px"></td></tr>


							</table></div></fieldset>
							<br><br><table style="width: 100%; height: 72px;">
									<tr>
										<td class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="acttaken">Immediate Action Taken: <?php if(isset($problems['acttaken'])) {?><font color="red">*</font><?php } ?></label><br>
		<textarea name="acttaken"  style=" width: 450px; height: 220px;" ></textarea></font><br></td>
									</tr>
								</table>

							<br><br>
							<table style="width: 100%; height: 72px;">
									<tr>
										<td class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
		<label class="formtext" for="followact">Follow-up Action Taken: <?php if(isset($problems['followact'])) {?><font color="red">*</font><?php } ?></label><br>
		<textarea name="followact"  style=" width: 450px; height: 220px;" ></textarea></font><br></td>
									</tr>
								</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.