Modify user submitted form data before it is saved an emails are sent I am new to drupal but I do have php experience. I am trying to modify an existing custom module that handles some forms on our site. The form in question is used to send an email to the address that is included as a hidden item. 

I need to change this email address based on an option the user chooses.

Here is an outline of what I need to happen

user goes to form (hidden email field is already set)
user enters their options
user clicks submit button
check users options and modify email field accordingly
save values to database
send email to new modified email address

Below is the code I am working with now

function bp_bottled_water_redirect(&amp;$form, &amp;$form_state, $form_id){
$interest = $form_state['input']['submitted']['primary_interest'];
$email = $form['submitted']['dealer_e_mail']['#webform_component']['value'];
//drupal_set_message("email is " . $email);
//drupal_set_message("interest is " . $interest);

if($interest == "bottled_water" &amp;&amp; $email == "info.minnetonka@culliganwater.com"){
    //$form_state['input']['submitted']['dealer_e_mail'] = "info.bottledwater@culliganwater.com";
    //$email = $form_state['input']['submitted']['dealer_e_mail'];
    $form_state['values']['dealer_e_mail'][LANGUAGE_NONE][0]['value'] = "info.bottledwater@culliganwater.com";
    drupal_set_message("changed email to: " . $form_state['values']['dealer_e_mail'][LANGUAGE_NONE][0]['value']);

}
else{
    $form['submitted']['dealer_e_mail']['#webform_component']['value'] = $email;
    drupal_set_message("email remains: " . $email);
    drupal_set_message("interest is " . $interest);
    }
}

/**
 * Implements hook_form_alter().
 */
function dealers_form_alter(&amp;$form, &amp;$form_state, $form_id) {
//drupal_set_message("Form ID is : " . $form_id);

if ($form_id == 'webform_client_form_960') {
//drupal_set_message("found form");
$form['#submit'][]='bp_bottled_water_redirect';

}

  // Act only on 'webforms'
  if (isset($form['#node']-&gt;type) &amp;&amp; $form['#node']-&gt;type == 'webform') {

    $require_zip = FALSE;
    if (isset($form['#node']-&gt;field_form_display_options['und'])){
      foreach ($form['#node']-&gt;field_form_display_options['und'] as &amp;$key) {
        if ($key['tid'] == 13) {
          $require_zip = TRUE;
        }
      }
    }
    switch($require_zip){
      case TRUE:
        $zip = _session_get('zip', '');
        if (dealers_is_local($zip) &amp;&amp; $require_zip == TRUE &amp;&amp; $zip !== '') {
          $zipinfo = json_decode(file_get_contents('http://zip.elevenbasetwo.com/'. $zip));
          $simplexml_obj = dealers_get_local($zip);
          $form['submitted']['5_digit_zip_code']['#default_value'] = $zip;
          // $form['submitted']['city']['#default_value'] = ucwords(strtolower($zipinfo-&gt;city));
          $form['submitted']['state']['#default_value'] = $zipinfo-&gt;state;
          $form['submitted']['dealer_e_mail']['#default_value'] = $simplexml_obj-&gt;DealerList-&gt;DealerRecord-&gt;EMail;
          $form['submitted']['dealer_e_mail']['#webform_component']['value'] = $simplexml_obj-&gt;DealerList-&gt;DealerRecord-&gt;EMail;
        }
        else {
          drupal_goto('dealers/'. substr($_SERVER['REQUEST_URI'], 1));
        }
        break;
    }
  }
}


The issue I am having is I can change the values according to the drupal_set_message. But it seems to be taking place after the data is saved. Because the email shown when viewing my submission is still the old one.  I think my code may be running to late.

How can I modify the email address before the data is saved?
You maybe able to add a submit handler or validate handler.

How do I add an additional submit handler in commerce checkout form?

https://stackoverflow.com/questions/15375616/how-to-use-form-validation-in-drupal-7

See the form examples >  https://api.drupal.org/api/examples/form_example!form_example_tutorial.inc/7