PrimeR Posted August 17, 2009 Share Posted August 17, 2009 I'm brand new to php. I have a contact form with text fields for user info, a working array menu, and a submit button. In my 2nd php file with all the commands in it, it is currently set up to send the user info to an email address. It works fine. But how do I change it to send the info to a ONE of a list of email address depending on WHICH MENU ITEM IS SELECTED. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170658-solved-submit-sends-to-specific-email-depending-on-drop-down-list-selection/ Share on other sites More sharing options...
p2grace Posted August 17, 2009 Share Posted August 17, 2009 Get the value of the $_POST selectbox, and then write a quick if or switch statement to determine the email address. Quote Link to comment https://forums.phpfreaks.com/topic/170658-solved-submit-sends-to-specific-email-depending-on-drop-down-list-selection/#findComment-900231 Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 I am assuming that you want to send an e-mail to specific groups of people. $list1 = array(..);//list of e-mail addresses $list2 = array(..); define('EMAIL_LIST_SUBSCRIBERS', 'subscribers'); define('EMAIL_LIST_MANUFACTURERS', 'manufacturers'); $final_list = array(); if ('POST' === $_SERVER['REQUEST_METHOD']) { if (!empty($_POST['list'])) { switch ($_POST['list']) { case EMAIL_LIST_SUBSCRIBERS: $final_list = $list1; break; case EMAIL_LIST_MANUFACTURERS: $final_list = $list2; break; } if (!empty($final_list)) { foreach ($final_list as $email_address) { mail($email_address, ..); } } } } Quote Link to comment https://forums.phpfreaks.com/topic/170658-solved-submit-sends-to-specific-email-depending-on-drop-down-list-selection/#findComment-900264 Share on other sites More sharing options...
PrimeR Posted August 17, 2009 Author Share Posted August 17, 2009 Actually, I want to email the info to only one recipient (from a few different possibilities). Which recipient gets the email would depend on the drop down menu selection in the form. Do you have sample code for doing this? Quote Link to comment https://forums.phpfreaks.com/topic/170658-solved-submit-sends-to-specific-email-depending-on-drop-down-list-selection/#findComment-900343 Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 $email_addresses = array(..); if (!empty($_POST['mail_to']) { $mail_to = (int) $_POST['mail_to']; if (isset($email_addresses[$mail_to])) { $email_address = $email_addresses[$mail_to]; mail($email_address, ..); } } else { foreach ($email_addresses as $key => $email_address) { echo '<option value="', $key, '">', substr($email_address, 0, $pos = strpos($email_address, '@') ? $pos : null), '</option>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/170658-solved-submit-sends-to-specific-email-depending-on-drop-down-list-selection/#findComment-900382 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.