Jump to content

[SOLVED] variable email based on user input


Kar606

Recommended Posts

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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.