Jump to content

form receipient checkboxes


SKHarris

Recommended Posts

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/html4/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.";
}
?>
Link to comment
Share on other sites

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:

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

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.
Link to comment
Share on other sites

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) [snapback]375261[/snapback][/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:

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

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.