I have a form that users fill out to send denial letters to customers. I have been struggling to figure out how to pass CHECKED checkboxes from a form to be passed to the $mail_body of the email.
Here is what i'm working with:
<?php
require_once "formvalidator.php";
$error_hash = 'no';
$show_form = true;
if (isset($_REQUEST['Submit'])) {
$validator = new FormValidator();
$validator->addValidation("Email", "req", "<B>Please provide an Email Address.</B>");
$validator->addValidation("Email", "email", "<B>Email address is invalid.</B>");
$validator->addValidation("Name", "req", "<B>Please provide a Recipient.</B>");
if ($validator->ValidateForm()) {
$show_form = false;
} else {
echo "<center><font color='#CC0000'><B>Validation Errors:</B></font></center>";
$error_hash = $validator->GetErrors();
foreach ($error_hash as $inpname => $inp_err) {
echo "<center><p>$inpname : $inp_err</p></center>\n";
$show_form = true;
}
}
if ($show_form === false){
// Grab the form vars
$From = "companyemail@email.com";
$Email = $_REQUEST['Email'];
$address ="Address of company";
$Date = date("Y/m/d");
$Name = $_REQUEST['Name'];
$Addy = $_REQUEST['Addy'];
$City = $_REQUEST['City'];
$State = $_REQUEST['State'];
$Zip = $_REQUEST['Zip'];
$num = $_REQUEST['Num'];
$message = "You have been denied for the following reasons:";
$reason1 = $_REQUEST['ch1'];
$reason2 = $_REQUEST['ch2'];
$reason3 = $_REQUEST['ch3'];
$reason4 = $_REQUEST['ch4'];
$reason5 = $_REQUEST['ch5'];
//message body
$mail_body .= "$address"."\r\n";
$mail_body .= "$Date"."\r\n";
$mail_body .= "$message"."\r\n";
$mail_body .= "$reason1"."\r\n";
$mail_body .= "$reason2"."\r\n";
$mail_body .= "$reason3"."\r\n";
$mail_body .= "$reason4"."\r\n";
$mail_body .= "$reason5"."\r\n";
$mail_body .= "$Name"."\r\n";
$mail_body .= "$Addy"."\r\n";
$mail_body .= "$City,". " $State". " $Zip"."\r\n";
$mail_body .= "RE: ".$num."\r\n";
//sending to
$recipient = "$Email";
$subject = "Credit Information";
//optional headerfields
$header = "From: " . $From . " <" . $From . ">\r\n";
//mail command
mail($recipient, $subject, $mail_body, $header);
}
echo "<div style='width:400px; margin:0 auto; border:1px solid #1e1e1e'>Your message has been sent successfully.<br>You will be redirected to the home page in a few moments...</div>";
//page redirect to home
echo "<meta http-equiv=\"refresh\" content=\"4;url=";
echo "http://lmtl-linux/credit\" />";
}
if (true == $show_form) {
?>
<div style="width:600px; margin:0 auto; border:1px solid black; background-color:#333333">
<p style="color:#FAFAFA; font-size:22px;">Customer Denial Emailer</p>
<form action="" method="GET" id="form">
<table>
<tr><td valign="top" class="title">Email:</td><td><input type="text" id="Email" name="Email" class="required email" value="<?php echo $_REQUEST['Email'];?>"></td></tr>
<tr><td valign="top" class="title">Name:</td><td><input type="text" id="Name" name="Name" class="required" value="<?php echo $_REQUEST['Name'];?>"></td></tr>
<tr><td valign="top" class="title">Address:</td><td><input type="text" id="Addy" name="Addy" class="required" value="<?php echo $_REQUEST['Addy'];?>"></td></tr>
<tr><td valign="top" class="title">City:</td><td><input type="text" id="City" name="City" class="required" value="<?php echo $_REQUEST['City'];?>"></td></tr>
<tr><td valign="top" class="title">State:</td><td><input type="text" id="State" name="State" class="required" value="<?php echo $_REQUEST['State'];?>"></td></tr>
<tr><td valign="top" class="title">Zip:</td><td><input type="text" id="Zip" name="Zip" class="required" value="<?php echo $_REQUEST['Zip'];?>"></td></tr>
<tr><td valign="top" class="title">App #:</td><td><input type="text" id="Num" name="Num" class="required" value="<?php echo $_REQUEST['Num'];?>"></td></tr>
<tr><td valign="top" class="title">Reason:</td></tr>
<tr><td colspan="2" class="reason"><input type="checkbox" id="ch1" name="ch1" value="Income insufficient to sustain payments" <?PHP if(isset($_REQUEST['ch1'])){print "checked";}?>>Income insufficent</td></tr>
<tr><td colspan="2" class="reason"><input type="checkbox" id="ch2" name="ch2" value="Employment is not of sufficient length to qualify" <?PHP if(isset($_REQUEST['ch2'])){print "checked";}?>>Employment lenght insufficent</td></tr>
<tr><td colspan="2" class="reason"><input type="checkbox" id="ch3" name="ch3" value="Limited or no credit history" <?PHP if(isset($_REQUEST['ch3'])){print "checked";}?>>Limited or no credit history</td></tr>
<tr><td colspan="2" class="reason"><input type="checkbox" id="ch4" name="ch4" value="Derogatory credit reporting" <?PHP if(isset($_REQUEST['ch4'])){print "checked";}?>>Derogatory credit reporting</td></tr>
<tr><td colspan="2" class="reason"><input type="checkbox" id="ch5" name="ch4" value="Bankruptcy, judgments, repossession, liens" <?PHP if(isset($_REQUEST['ch5'])){print "checked";}?>>Bankruptcy, reposession, etc.</td></tr>
</table>
</div>
<div style="width:650px; margin:0 auto;">
<input type="submit" name="Submit" id="Submit" value="Send Email" style="margin-left:22px; width:100px;">
</form>
</div>
<?php
}//true == $show_form
?>
</body>
</html>
if i check a couple "reasons" none of those reasons get passed to the email. Any ideas?