ChompGator Posted July 27, 2008 Share Posted July 27, 2008 Hey, I have a fairly simple script that allows users to fill in their email, then the message then submit the form and it submits to an email address...What Ive added now is a drop down menu that allows users to select which department they want their email to go to. Iam unsure how to code the sendmail.php (the script that actually sends the email) <?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; mail( "[email protected]", "REQUEST", $message, "From: $email" ); header( "Location: http://www.mysite.com/thankyou.html" ); ?> That is just how it appears now, Im trying to configure it for the drop down I added, Ill be re-searching this but any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/ Share on other sites More sharing options...
MFHJoe Posted July 27, 2008 Share Posted July 27, 2008 Use the HTML: <select name="department"> <option value="Sales">Sales</option> <option value="Marketing">Marketing</option> <option value="Support">Support</option> </select> Then add to your PHP something like: <?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $department = $_REQUEST['department']; if($department == 'Sales') { $sendto = '[email protected]'; } elseif($department == 'Marketing') { $sendto = '[email protected]'; } elseif($department == 'Support') { $sendto = '[email protected]'; } mail( $sendto, "REQUEST", $message, "From: $email" ); header( "Location: http://www.mysite.com/thankyou.html" ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600872 Share on other sites More sharing options...
.josh Posted July 27, 2008 Share Posted July 27, 2008 Instead of that big condition statement that you will have to keep adding to as departments are added, just do this: $department = $_REQUEST['department']; $allowed = array('sales','marketing','support'); // add more departments here // change [email protected] to default email address $sendto = (in_array($department, $allowed))? $department . "@yoursite.com" : "[email protected]"; Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600876 Share on other sites More sharing options...
ChompGator Posted July 27, 2008 Author Share Posted July 27, 2008 Thanks both of you for the code's. I appreciate the help... Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600896 Share on other sites More sharing options...
ChompGator Posted July 27, 2008 Author Share Posted July 27, 2008 One last question (sorry!) When a user selects a department and fills out his message and then clicks 'submit' if I want to submit the email (only for that specific department) to three email addresses would I do this: $sendto = '[email protected]; [email protected]; [email protected]'; or $sendto = '[email protected]' '[email protected]' '[email protected]'; I tried both ways and it doesn't seem to be submitting to any of the three email addresses Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600906 Share on other sites More sharing options...
Nhoj Posted July 27, 2008 Share Posted July 27, 2008 The first option would be best, although I think you may need to use a comma instead of a semicolon to separate the addresses. Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600924 Share on other sites More sharing options...
ChompGator Posted July 27, 2008 Author Share Posted July 27, 2008 Thank you sir! Quote Link to comment https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600930 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.