Jump to content


Photo

form receipient checkboxes


  • Please log in to reply
2 replies to this topic

#1 SKHarris

SKHarris
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 May 2006 - 03:32 PM

This is my first try at php. The form works when I have just one recipient. But I don't quite have the code right for having multiple recipients selected by using checkboxes. And help would be hugely appreciated. Below is the code for formpage.php, and mail.php.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Form</title>
</head>
<body>
<form action="mail.php" method="post">
Your Name:<br>
<input type="text" name="name"><br><br>
E-mail:<br>
<input type="text" name = "email"><br><br>
Comments<br>
<textarea name="comments"></textarea><br><br>
<input type="checkbox" name="incoming_mailto[]" value="gmail">Send form to gmail address</input><br>
<input type="checkbox" name="incoming_mailto[]" value="yahoo">Send form to yahoo address</input><br>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>


<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}
// make array of all possible mails that could be used - a security check
$permittedmailsarray = Array(
'gmail' => 'skharrisla@gmail.com',
'yahoo'=> 'webtechla@yahoo.com'
);
if(is_array($_POST['incoming_mailto'])) {
foreach($_POST['incoming_mailto'] as $v){
$recipients = $permittedmailsarray[$v];
}
}
$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['comments'];
checkOK($comments);
$to="skh@webtechla.com";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks for your feedback.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 04:00 PM

well first off, at no point in time in your mail function do you include incoming_mailto

2nd, you have this:

if(is_array($_POST['incoming_mailto'])) {
foreach($_POST['incoming_mailto'] as $v){
$recipients = $permittedmailsarray[$v];
}
}

which seems to serve no purpose in your script. i think what you were trying to do is check the incoming_mailto values up against the permittedmailsarray but all you do is set $recipients to that value. i think what you probably wanted to do was something like this:

if(is_array($_POST['incoming_mailto'])) {
   foreach($_POST['incoming_mailto'] as $v){
      foreach($permittedmailsarray as $x) {
         if ($v == $x) {
            $recipients[] = $v;
         }
      }  
   }
}

and then you will end up with the array $recipients that holds each email address the user entered in, that is permitted on your list of permitted emails.

then you actually have to put $recipients into your mail function.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 SKHarris

SKHarris
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 May 2006 - 11:12 AM

Thanks for your help. Its working now.







[!--quoteo(post=375261:date=May 19 2006, 11:00 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 19 2006, 11:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
well first off, at no point in time in your mail function do you include incoming_mailto

2nd, you have this:

if(is_array($_POST['incoming_mailto'])) {
foreach($_POST['incoming_mailto'] as $v){
$recipients = $permittedmailsarray[$v];
}
}

which seems to serve no purpose in your script. i think what you were trying to do is check the incoming_mailto values up against the permittedmailsarray but all you do is set $recipients to that value. i think what you probably wanted to do was something like this:

if(is_array($_POST['incoming_mailto'])) {
   foreach($_POST['incoming_mailto'] as $v){
      foreach($permittedmailsarray as $x) {
         if ($v == $x) {
            $recipients[] = $v;
         }
      }  
   }
}

and then you will end up with the array $recipients that holds each email address the user entered in, that is permitted on your list of permitted emails.

then you actually have to put $recipients into your mail function.
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users