Email Form

Hello, I found the code below for a simple email form. It seems that something is throwing it off. I have changed this code here so that everyone sees the basic structure but assuming all of the values are correct (such as emails and variables) I want the error codes to pop up if a field isn’t filled in and simply sent to where i need it to go. With all of the information that I have in it, hitting submit on the form it looks like it goes through but the emails never come.

<?php
error_reporting(E_ALL ^ E_NOTICE);  

if (trim($_POST['Item1'])=='' OR
    trim($_POST['Item2'])=='' OR
	trim($_POST['Item3'])=='' OR
    trim($_POST['Item4'])=='') {

$errors='';

    if (trim($_POST['name'])=='')
    $errors.='<li>Please Provide Item 1.</li>';

    if (trim($_POST['comments'])=='')
    $errors.='<li>Please Provide Item 2.</li>';

    if (trim($_POST['nominee'])=='')
    $errors.='<li>Please Provide Item 3.</li>';

    if (trim($_POST['office'])=='')
    $errors.='<li>Please Provide Item 4.</li>';
	

echo 'Your forgot to fill out a field. Please review what you missed below:';

echo '<ul>';
echo $errors;
echo '</ul>';

}
else {

// Function to check spam
function checkforspam() {
   $problem = 'N';
   foreach ($_POST as $key => $value) {
     if (stristr($value,'Content-Type:') || stristr($value,'bcc:')) {
       $problem = 'Y';
     }
   }
   if ($problem == 'Y') {
     return 'Y';
   } else {
     return 'N';
   }
} 

/* Subject and Email Variables */

	$emailSubject = 'New Submission Email';
	$webMaster  = 'email@domain.com';
	
	
/*Gathering Data Variables*/
	
	$var1 = $_POST['Item 1'];
	$var2 = $_POST['Item 2'];	
	$var3 = $_POST['Item 3'];
	$var4 = $_POST['Item 4'];
	
	$body = <<<EOD
<font color="#75876D" size="4" face="Arial, Helvetica, sans-serif"><strong><br>Submission for Email<hr><br></strong></font>
<font color="#75876D" size="2" face="Arial, Helvetica, sans-serif">
<strong>Item1:</strong><br> $var1 <br><br><br>
<strong>Item2:</strong><br> $var2 <br><br><br>
<strong>Item3:</strong><br> $var3 <br><br><br><hr>
<strong>Item4:</strong><br> $var4 <br><br><br></font>

EOD;

	$headers = "From: $emailSubject\\r\
";
	$headers .= "Content-type: text/html\\r\
";
	$success = mail($webMaster, $emailSubject, $body, $headers);
	
	/* Results Rendered as HTML */
	$theResults = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Title</title>
<style type="text/css">
<!--
.form2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #404E5B;
	border: 1px solid #CFD8CF;
	width: 165px;
	height: 18px;
}
.form1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #404E5B;
	border: 1px solid #CFD8CF;
	width: 30px;
	height: 18px;
}

.form3{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #404E5B;
	border: 1px solid #CFD8CF;
	width: 150px;
	height: 18px;
}


.white {font-family: Tahoma; color: #FFFFFF; font-size: 12px; }
.green {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 26px;
	color: #006B37;
}

.green_15px {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 15px;
	color: #006B37;
}
.green_bold {font-family: Arial, Helvetica, sans-serif; font-size: 26px; color: #006B37; font-weight: bold; }
.style13 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #006B37; }
a:link {
	color: #A6942E;
}
body {
	background-image: url(images/pat20.jpg);
}
.style24 {font-family: Arial, Helvetica, sans-serif; font-size: 22px; color: #75876D; font-weight: bold; }

-->
</style>

</head>

<body>
Some text would go here.
</body>
</html>



EOD;
echo "$theResults";
}

?>

You are checking one set of variables, then looping through a different set of variables to find which is empty.

In some places you’re looking at $_POST[‘Item1’], others you’re looking at $_POST[‘name’]. You’ll need to change every instance to the same thing if you want it to work.

Oooh ok ok that makes sense. I got it changed and now its working. One more question, how can I send it to two recipients? Is this correct:

$webMaster  = 'email@domain.com, email2@domain.com';

Seems that when I put that in, the form stopped working but with one recipient its fine.

Thank you for your help!

Hm, that should work. But there are various other ways to do this.

E.g.:


$webMaster  = 'email@domain.com';
$webMaster2  = 'email2@domain.com';

mail($webMaster, $emailSubject, $body, $headers);
mail($webMaster2, $emailSubject, $body, $headers);

Or you can add CCs or BCCs:


$headers .= 'Cc: email2@domain.com' . "\\r\
";
$headers .= 'Bcc: email3@domain.com' . "\\r\
";