How to email through PHP using checkboxes
Posted: Fri Mar 06, 2009 12:54 pm
Hi, im having a difficult time with this, any help would be much appreciated. I have a form with a couple of checkboxes, when a manager is filling out the form and wants to assign an application to a staff under them, they select the checkbox with the apps they want thier staff to have. The thing is, each application then has to be approved by the application designator, so with 10 applications, there will be 10 different email addresses.
Is it possible to have the manager click submit and have an email sent to the appropriate person based on a checkbox selection? Here is what i have below so far, currently it works but nothing is sent to any email addresses...
contact.php
<form method="POST" action="mailer.php">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Name:</td>
<td><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" name="title" size="19"></td>
</tr>
<tr>
<td>Supervisor:</td>
<td><input type="text" name="supervisor" size="19"></td>
</tr>
<tr>
<td>Location:</td>
<td><input type="text" name="location" size="19"></td>
</tr>
<tr>
<td>Please Select The Applications Needed:</td>
<td>
<input type="checkbox" name="check[]" value="ADP"> ADP<br>
<input type="checkbox" name="check[]" value="AIRS"> AIRS<br>
<input type="checkbox" name="check[]" value="Awards"> Awards<br>
</td>
<td>
<input type="checkbox" name="check[]" value="eCOMPAS"> eCOMPAS<br>
<input type="checkbox" name="check[]" value="FundEZ"> FundEZ<br>
<input type="checkbox" name="check[]" value="HCPlus"> HCPlus<br>
</td>
<td>
<input type="checkbox" name="check[]" value="IATS"> IATS<br>
<input type="checkbox" name="check[]" value="IEP Plus"> IEP Plus<br>
<input type="checkbox" name="check[]" value="Nexsus"> Nexsus<br>
</td>
</tr>
<tr>
<td>Message:</td>
</tr>
<td><textarea name="message" style="height: 43px; width: 225px"></textarea></td>
</table>
<input type="submit" value="Submit" name="submit">
</form>
Mailer.php
<?php
if(isset($_POST['submit'])) {
//$to = "user@user.com";
$subject = "Application Request";
$name_field = $_POST['name'];
$title_field = $_POST['title'];
$supervisor_field = $_POST['supervisor'];
$location_field = $_POST['location'];
$message = $_POST['message'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
//if ($_SERVER['REQUEST_METHOD'] != 'POST'){
// $me = $_SERVER['PHP_SELF'];
switch($_POST['check']){
case 'ADP':
$to = 'user1@user.com';
break;
case 'AIRS':
$to = 'user2@user.com';
break;
case 'Awards':
$to = 'user3@user.com';
break;
//default:
// $to = 'user@user.com';
}
$body = "From: $name_field\n Title: $title_field\n Supervisor: $supervisor_field\n Location: $location_field\n Message:\n $message\n $check_msg";
echo "Your $subject has been submitted";
mail($to, $subject, $body);
} else {
echo "Sorry!";
}
?>
Is it possible to have the manager click submit and have an email sent to the appropriate person based on a checkbox selection? Here is what i have below so far, currently it works but nothing is sent to any email addresses...
contact.php
<form method="POST" action="mailer.php">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Name:</td>
<td><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" name="title" size="19"></td>
</tr>
<tr>
<td>Supervisor:</td>
<td><input type="text" name="supervisor" size="19"></td>
</tr>
<tr>
<td>Location:</td>
<td><input type="text" name="location" size="19"></td>
</tr>
<tr>
<td>Please Select The Applications Needed:</td>
<td>
<input type="checkbox" name="check[]" value="ADP"> ADP<br>
<input type="checkbox" name="check[]" value="AIRS"> AIRS<br>
<input type="checkbox" name="check[]" value="Awards"> Awards<br>
</td>
<td>
<input type="checkbox" name="check[]" value="eCOMPAS"> eCOMPAS<br>
<input type="checkbox" name="check[]" value="FundEZ"> FundEZ<br>
<input type="checkbox" name="check[]" value="HCPlus"> HCPlus<br>
</td>
<td>
<input type="checkbox" name="check[]" value="IATS"> IATS<br>
<input type="checkbox" name="check[]" value="IEP Plus"> IEP Plus<br>
<input type="checkbox" name="check[]" value="Nexsus"> Nexsus<br>
</td>
</tr>
<tr>
<td>Message:</td>
</tr>
<td><textarea name="message" style="height: 43px; width: 225px"></textarea></td>
</table>
<input type="submit" value="Submit" name="submit">
</form>
Mailer.php
<?php
if(isset($_POST['submit'])) {
//$to = "user@user.com";
$subject = "Application Request";
$name_field = $_POST['name'];
$title_field = $_POST['title'];
$supervisor_field = $_POST['supervisor'];
$location_field = $_POST['location'];
$message = $_POST['message'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
//if ($_SERVER['REQUEST_METHOD'] != 'POST'){
// $me = $_SERVER['PHP_SELF'];
switch($_POST['check']){
case 'ADP':
$to = 'user1@user.com';
break;
case 'AIRS':
$to = 'user2@user.com';
break;
case 'Awards':
$to = 'user3@user.com';
break;
//default:
// $to = 'user@user.com';
}
$body = "From: $name_field\n Title: $title_field\n Supervisor: $supervisor_field\n Location: $location_field\n Message:\n $message\n $check_msg";
echo "Your $subject has been submitted";
mail($to, $subject, $body);
} else {
echo "Sorry!";
}
?>