954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

check box form

I have a checkbox form where different check boxes need to send the form to different email addresses. Right now, no matter the check box, it goes to the same emails.



Blah

going here:

natep
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

A. If u had a javascript on your form, that generates the '$mailto' values based on the checkbox 'checked' property, it might make life easier for you - with validation possibilities.

B. For the moment the '$mailto' is hard coded and no decision making is made to define the email recipients. No wonder it is going to the same emails whatever be the checkbox combinations.

C. In case you have a lot of checkbox and combinations, it is practical to standardize your checkbox ids/names and a simple loop in the client or server script would easily define the email combination you require.

Hope the above tips help.

askorumtollee
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

What you say makes sense but I don't really know php at all. I was hoping there would just be a few lines of code I could copy & pop in. So, it's more difficult than that? Thanks.

natep
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

It's not really difficult . All you need is just a loop to go through all the checked boxes, and generate/concatenate the $mailto recipient list.

how are the checkbox names? If the loop does not work, the easiest but long way is to have a list of if statements, generating/concatenating the $mailto recipient list for you.

askorumtollee
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Would you have time to look at the actual code?

[email]nate@therussogroup.com[/email]

natep
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Okie, I'm sending you a private message on the email add provided. Please confirm receipt.

askorumtollee
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

This is mail.html. Here you can add the checkboxes specifying the email address as values to those checkboxes.

<!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>Send mail</title>
</head>

<body>
<form action="mail.php" method="post">
<INPUT TYPE="checkbox" NAME="chk1" value="example1@example.com">Name 1 
<INPUT TYPE="checkbox" NAME="chk2" value="example2@example.com">Name 2 
<INPUT TYPE="checkbox" NAME="chk3" value="example3@example.com">Name 3 
<INPUT TYPE="checkbox" NAME="chk4" value="example4@example.com">Name 4 
<INPUT TYPE="checkbox" NAME="chk5" value="example5@example.com">Name 5 
<INPUT TYPE="checkbox" NAME="chk6" value="example6@example.com">Name 6 
<INPUT TYPE="checkbox" NAME="chk7" value="example7@example.com">Name 7 
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>


This is mail.php. Here you loop through all the posted variables, check if its value is submit, if it is submit, then skip it, else, send a mail !

<?php //mail.php
foreach ($_POST as $key => $value){
	if($value !="Submit"){
		$to = $value;
		$email="noreply@yoursite.com";
		$subject="Test mail !!!!";
		$message = "Hey ! I dont have any message !";
		mail($to,$subject,$message,"From:".$email);
	}
}
?>


Cheers,
Naveen

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You