I need to add a line to a form-mail script. I basically want it to route to xyz's email if address if "state" field equals FL, NY and if it equals SC or NC then send to wxyz..and so on...any tips..? if you need to see the form-mail script...it is here http://www.dbmasters.net/index.php?id=4 open to suggestion on anther script too.. thanks
Depending on what you want to do, you could use: <?php // Post state variable $state = $_POST['state']; // Assign a numerical value to each state via an array (FL = 1, SC = 3, etc.) $states_arr = array("FL", "NY", "SC", "NC"); // Perform the desired action based on the numerical value mentioned above switch ($states_arr[$state]){ case 0: case 1: /* Mail to xyz */ break; case 2: case 3: /* Mail to wxyz */ break; default: /* Default Action */ break; } ?> PHP: Or you could use the following: <?php // Post state variable $state = $_POST['state']; // Assign states to different arrays for each e-mail address $xyz_arr = array("FL", "NY"); $wxyz_arr = array("SC", "NC"); // Perform the desired action based on the array $state is in if ( in_array($state, $xyz_arr) ){ /* Mail to xyz */ } else if ( in_array($state, $wxyz_arr) ){ /* Mail to wxyz */ } else { /* Default Action */ } ?> PHP:
thanks for the suggestions. is this the easiest way ?, if for example, I have 2 people each from 20 states ( total 40) to send info to: so I would then have 40 email addresses to input ? I wish it was as easy as grouping into arrays
Take a look at this and tell me if you like it: <?php // Post state variable $state = $_POST['state']; // Assign states to different e-mail addresses using arrays $states_arr = array( array("FL", "NY", "xyz@email.com"), array("SC", "NC", "wxyz@email.com") ); // If $state is in one of the above arrays, set the e-mail to its last element foreach ($states_arr as $test){ if ( in_array($state, $test) ){ $email = end($test); break; } else { // If not, e-mail to the default address $email = "default@email.com"; } } // Mail based on the state's array $subject = "Subject"; $message = "Blah, blah, blah!"; mail($email, $subject, $message); ?> PHP: