teanza Posted February 20, 2009 Share Posted February 20, 2009 hey dudes- i posted something a few weex ago, and i finally figured-out my stuff for the most part. however, i need to have my form go 2 a different email per a required drop-down menu selection. i have the values as 0,1,2,3. when the form submits, it is only going 2 the top email ("[email protected]") with the corresponding subject, no matter the drop-down selection the user chooses! any ideas? (below) thanx! :-* <?php if(isset($_POST['email'])) { switch ($_POST['to']) { case 0: $to = "[email protected]"; $subject = "Website Inquiry: A"; break; case 1: $to = "[email protected]"; $subject = "Website Inquiry: B"; break; case 2: $to = "[email protected]"; $subject = "Website Inquiry: C"; break; case 3: $to = "[email protected]"; $subject = "Website Inquiry: D"; break; } $body = "*** " . $subject . " *** \n \n"; $body .= "Name: "; $body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"]; $body .= "\n \n"; $body .= "Phone Number: "; $body .= $_REQUEST["telephone"]; $body .= "\n \n"; $body .= "Email Address: "; $body .= $_REQUEST["email"]; $body .= "\n \n"; $body .= "Comments: \n \n"; $body .= $_REQUEST["additionalwords"]; $body .= "\n \n"; $body .= "Complexes: \n \n"; $body .= $_REQUEST["complexes"]; $msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>"; $msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>"; $header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n"; if (mail($to, $subject, $body, $header)) { echo $msgSuccess; } else { echo $msgError; } } { ?> ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/ Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 Dont no much about switch but try this <?php if(isset($_POST['email'])) { switch ($_POST['to']) { case "0": $to = "[email protected]"; $subject = "Website Inquiry: A"; break; case"1": $to = "[email protected]"; $subject = "Website Inquiry: B"; break; case "2": $to = "[email protected]"; $subject = "Website Inquiry: C"; break; case "3": $to = "[email protected]"; $subject = "Website Inquiry: D"; break; } $body = "*** " . $subject . " *** \n \n"; $body .= "Name: "; $body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"]; $body .= "\n \n"; $body .= "Phone Number: "; $body .= $_REQUEST["telephone"]; $body .= "\n \n"; $body .= "Email Address: "; $body .= $_REQUEST["email"]; $body .= "\n \n"; $body .= "Comments: \n \n"; $body .= $_REQUEST["additionalwords"]; $body .= "\n \n"; $body .= "Complexes: \n \n"; $body .= $_REQUEST["complexes"]; $msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>"; $msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>"; $header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n"; if (mail($to, $subject, $body, $header)) { echo $msgSuccess; } else { echo $msgError; } } { ?> Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766771 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 thanx man i appreciate that , but the quotes actually made it not work @ all ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766774 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 Tested and worked :-) <?php switch ($_POST['to']) { case '0': $to = "[email protected]"; $subject = "Website Inquiry: A"; break; case'1': $to = "[email protected]"; $subject = "Website Inquiry: B"; break; case '2': $to = "[email protected]"; $subject = "Website Inquiry: C"; break; case '3': $to = "[email protected]"; $subject = "Website Inquiry: D"; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766777 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 hm weird; that doesn't work @ all either! when i have no quotes, it sends to the 'A' email address only. single ' or double " don't work. hm? ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766780 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 what does <?php print $_POST['to']; ?> show? We want to see if it posts something different when the dropdown selection is different Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766781 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 hey thanx again. "print" actually doesn't work @ all (won't display page). is that what u were asking? i am 2 new 2 this. ~tina~ ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766786 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 We need to see what is being passed to the script from the HTML form. can you post the code for your html form? Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766791 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 the site is here andrews-management.com/contactus.php i am messing w/the rest of the site so try 2 ignore it ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766795 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 Put them into a database, and have them pull the data based on the auto increment of the row. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766798 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 I cant access the site, Just paste the code for the contact form. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766800 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 ok i used the code function this time thanx <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact"> <span id="sprytextfield1"> <label> </span><br /> <br /> <div align="right"><span><span class="style20"><span class="style21">F</span>irst name</span> <input type="text" name="firstname" id="firstname" /> </span></div> <span> </label> <span class="textfieldRequiredMsg">Kindly enter your first name </span></span><br /> <br /> <span id="sprytextfield2"> <label> </span> <div align="right"><span class="style20"><span class="style21">L</span>ast name </span> <input type="text" name="lastname" id="lastname" /> </div> <span> </label> <span class="textfieldRequiredMsg">Kindly enter your last name </span></span> <br /> <br /> <span id="sprytextfield3"> <label> </span> <div align="right"><span class="style20"><span class="style21">E</span>mail address</span> <input type="text" name="email" id="email" /> </div> <span> </label> <span class="textfieldRequiredMsg">Kindly enter your email address </span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span> <br /> <br /> <span id="sprytextfield4"> <label> </span> <div align="right"><span class="style20"><span class="style21">P</span>hone number</span> <input type="text" name="telephone" id="telephone" /> </div> <span></label><span class="textfieldRequiredMsg">Kindly enter your phone number </span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span> <br /> <br /> <span id="spryselect1"> <label> </span> <div align="right"><span class="style20"><span class="style21">C</span>omplex of interest</span> <select name="complexes" id="complexes"> <option value="-1" selected="selected">Please choose one</option> <option value="0">None/General inquiry</option> <option value="1">Seville Square</option> <option value="2">Stonehenge</option> <option value="3">Logan Road</option> </select> </div> <span> </label> <span class="selectInvalidMsg">Kindly select a complex </span><span class="selectRequiredMsg">Kindly select a complex </span></span> <br /> <br /> <span> <label> </label> </span> <label><div align="right"><span class="style11 style22"><span class="style21">A</span>ny additional comments?</span><span> <textarea name="additionalwords" id="additionalwords" cols="45" rows="5"></textarea> </span></div> </label> <span> <span class="textareaRequiredMsg">A value is required.</span></span><br /> <label> <div align="center"> <input type="submit" name="submit" id="submit" value="Submit!" /> </div> </label> </form> ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766803 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 thanx q695; unfortunately that is beyond me :'( ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766805 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 Hi, Your drop down field is called "complexes" not "to" here <?php if(isset($_POST['email'])) { switch ($_POST['complexes']) { case '0': $to = "[email protected]"; $subject = "Website Inquiry: A"; break; case'1': $to = "[email protected]"; $subject = "Website Inquiry: B"; break; case '2': $to = "[email protected]"; $subject = "Website Inquiry: C"; break; case '3': $to = "[email protected]"; $subject = "Website Inquiry: D"; break; } $body = "*** " . $subject . " *** \n \n"; $body .= "Name: "; $body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"]; $body .= "\n \n"; $body .= "Phone Number: "; $body .= $_REQUEST["telephone"]; $body .= "\n \n"; $body .= "Email Address: "; $body .= $_REQUEST["email"]; $body .= "\n \n"; $body .= "Comments: \n \n"; $body .= $_REQUEST["additionalwords"]; $body .= "\n \n"; $body .= "Complexes: \n \n"; $body .= $_REQUEST["complexes"]; $msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>"; $msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>"; $header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n"; if (mail($to, $subject, $body, $header)) { echo $msgSuccess; } else { echo $msgError; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766814 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 u rock my world. i have very little idea w/what i am doing. i started out doing a nice basic site, lol. it worked. ur awesome! so now that u helped with it, maybe u can tell me how 2 redirect the stupid page? i did it in the meta tag but it keeps jumping back and forth. ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766819 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 Your drop down could be condensed to a while loop with a database back end. You need a unique identifier on the drop down. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766820 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 hopefully i can comprehend that wholly in the near future. i appreciate it though! ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766821 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 I like to do a captcha security around it that requires the captcha string to be retyped once you get it correct the first time. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766822 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 Thats great. I personally would have 2 separate files. 1 - contactform.html 2 - contactformmailer.php Place all the php code in to contactformmailer.php and change the lines <?php if (mail($to, $subject, $body, $header)) { echo $msgSuccess; } else { echo $msgError; } } ?> to <?php if (mail($to, $subject, $body, $header)) { header("Location:http:YOURSITE.com"); } else { echo $msgError . "<br /> To go back please click <a href=\"".$_SERVER['HTTP_REFERER']. " \">here</a>"; } ?> and in the contactform.html change <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact"> to <form action="contactformmailer.php" method="post" name="contact" id="contact"> Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766825 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 sorry i mean redirect the index page lol. do u think i should for the form? is it bad 2 have it w/that extension? ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766826 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 Sorry i dont get what you mean by redirect the index page, can you explain step by step what you want to happen? Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766827 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 I do an if to see if the message is filled, or not, so that it's all at one location, and it flows logically, but I also like to load all variables at the top of each page. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766828 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 You could also do a post variable that has a redirect built in if something is a particular value, or simply an include. Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766829 Share on other sites More sharing options...
teanza Posted February 20, 2009 Author Share Posted February 20, 2009 well i just need it 2 go 2 the https:// part. i used a meta tag but it keeps jumping: andrews-management.com i looked-up a php file, but i suppose i failed 2 use it properly! i need the users to never come across the page without the secure 's'. ~tina~ Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766839 Share on other sites More sharing options...
farkewie Posted February 20, 2009 Share Posted February 20, 2009 You should be able to do that in your hosting control panel. But if you cant this should do it. <?php header("Location:https://mysite.com"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/146061-solved-web-form-different-emails-per-a-choice/#findComment-766845 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.