How to email through PHP using checkboxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
motox1981
Forum Newbie
Posts: 4
Joined: Fri Mar 06, 2009 12:45 pm

How to email through PHP using checkboxes

Post by motox1981 »

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!";
}

?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to email through PHP using checkboxes

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
motox1981
Forum Newbie
Posts: 4
Joined: Fri Mar 06, 2009 12:45 pm

Re: How to email through PHP using checkboxes

Post by motox1981 »

Ok, im getting a HTTP 500 error... Im looking to see if there is a misplaced tag somewhere, any thoughts on your end?
motox1981
Forum Newbie
Posts: 4
Joined: Fri Mar 06, 2009 12:45 pm

Re: How to email through PHP using checkboxes

Post by motox1981 »

Got it, missing bracket after echo '</ul>';

Thanks Man!

Is there a way to credit you, or make this the solution?
Post Reply