SKHarris Posted May 19, 2006 Share Posted May 19, 2006 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.";}?> Quote Link to comment https://forums.phpfreaks.com/topic/10010-form-receipient-checkboxes/ Share on other sites More sharing options...
.josh Posted May 19, 2006 Share Posted May 19, 2006 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 https://forums.phpfreaks.com/topic/10010-form-receipient-checkboxes/#findComment-37194 Share on other sites More sharing options...
SKHarris Posted May 22, 2006 Author Share Posted May 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10010-form-receipient-checkboxes/#findComment-37915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.