Kar606 Posted April 29, 2009 Share Posted April 29, 2009 I have a form with a drop down menu, where the user can pick one from 10 teams. Depending on which team they are a part of I would like an email to be sent to the team leader as well as finishing out the rest of the script, which saves the submitted info to a cvs file. I am new to php and wondered if there was a better way of writing this than to use a series of if else statements to cycle through the values??? possibly putting the data into an associative array and comparing the submitted data to find the appropriate email address. Not quite sure what this code would look like. Any hints as to a direction to go would be appreciated! Link to comment https://forums.phpfreaks.com/topic/156146-solved-variable-email-based-on-user-input/ Share on other sites More sharing options...
rhodesa Posted April 29, 2009 Share Posted April 29, 2009 the associative array would be good if each item had a different email: <?php $emails = array( 'option1' => '[email protected]', 'option2' => '[email protected]', 'option3' => '[email protected]', ); $to = $emails[$_POST['option']]; ?> or, you can use a switch statement...this is good if each email is mapped to more then one option: <?php switch($_POST['option']){ case 'option1': $to = '[email protected]'; break; case 'option2': case 'option3': case 'option4': $to = '[email protected]'; break; case 'option5': case 'option6': case 'option7': $to = '[email protected]'; break; default: $to = '[email protected]'; } ?> in this, don't forget the BREAK statements Link to comment https://forums.phpfreaks.com/topic/156146-solved-variable-email-based-on-user-input/#findComment-821962 Share on other sites More sharing options...
Kar606 Posted April 29, 2009 Author Share Posted April 29, 2009 Thanks rhodesa! bold and nosy... good qualities if you ask me Link to comment https://forums.phpfreaks.com/topic/156146-solved-variable-email-based-on-user-input/#findComment-822204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.