simcoweb Posted May 21, 2009 Share Posted May 21, 2009 I'm inserting a form field utilizing a dropdown selector so the person can select which department they wish for the email to be directed to. Depending on their selection the form results would be emailed to the respective address. I am using this code to parse and send the form without the dropdown selection. <? @extract($_POST); $name = stripslashes($name); $email = stripslashes($email); $department = stripslashes($department); $message = stripslashes($message); if(mail("test@example.com","Email from $name"," $message (From $name, $email)","From: $email")){ echo "$name $email $message"; }*/ echo "Email Successfully Sent!<br /> <br /> Name: $name<br />Email: $email<br />Website: $website<br />Message: $message"; ?> And the form code: <form id="my-form"> <table> <tr><td>Name</td><td><input type="text" id="name" name="name" /></td></tr> <tr><td>Email<br /><small>(will never be published)</small></td><td><input type="text" id="email" name="email" /></td></tr> <tr><td>Department</td><td><select name="department"> <optgroup label="Department"> <option value="sales" name="sales">Sales</option> <option value="customer service" name="customer service">Customer Service</option> </optgroup></select></td></tr> <tr><td valign="top">Message</td><td><textarea cols="40" rows="5" name="message" id="message"></textarea></td></tr> <tr><td> </td><td><input type="button" value="Send" onclick="sendRequest();" /> <input type="button" id="resetbut" name="resetbut" value="Reset" onclick="resetForm();" /></td></tr> </table> </form> The key is that IF they select the Sales dept. then the email would be sent to sales@ and IF they select the Customer Service then it would go to customerservice@. Not sure how to code that properly to populate the $to slot in the mail(function). Just a bit of guidance, por favor Quote Link to comment Share on other sites More sharing options...
Masna Posted May 21, 2009 Share Posted May 21, 2009 $your_site = "mysite.com"; //change this $to = $_POST['department']."@".$your_site; Quote Link to comment Share on other sites More sharing options...
simcoweb Posted May 21, 2009 Author Share Posted May 21, 2009 Ok, so basically I don't need to worry that the 'field' name 'department' has multiple choices, it will take the 'value' assigned to whatever choice they select and populate the $to variable with the front-end of the email and complete it with the $your_site content. For some reason I was thinking I had to deal with an array issue of some sort since it was a drop down selection with multiple choices under one group name. Guess that's not the case, eh? Thanks for your response! Quote Link to comment Share on other sites More sharing options...
Masna Posted May 21, 2009 Share Posted May 21, 2009 Ok, so basically I don't need to worry that the 'field' name 'department' has multiple choices, it will take the 'value' assigned to whatever choice they select and populate the $to variable with the front-end of the email and complete it with the $your_site content. For some reason I was thinking I had to deal with an array issue of some sort since it was a drop down selection with multiple choices under one group name. Guess that's not the case, eh? Thanks for your response! Yes, you are correct. You do not have to use an array here (and if you happen to come across a browser that sends an array of information when sending the value selected of a drop-down field, let me know). Quote Link to comment 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.