Create email everytime a webform is sent off (in custom module) I'm trying to write some code that sends off an email every time a webform is submitted/edited.

I tried using hook_webform_component_presave() figuring I could just stick some mail code in this function and it would work... it didn't.

This is what I have 

mymodule_webform_component_presave(&amp;$component){
  mail('test@mail.com', 'subject', 'message');
}


I am aware that this can be done through a webforms setting, but that's not what I need.
I've solved this issue in Drupal 6 by adding a secondary submit function to the webform.  In that submit function, I use webform's email handler to send my email.

In hook_form_alter:

function custom_form_alter(&amp;$form, $form_state, $form_id) {
    switch($form_id) {
        case 'a_form': // the value we stole from the rendered form
        case 'another_form_form': //Fall through, instead of trying to do case A OR B:
        case 'the form I want to send emails from':
            $form['#submit'][] = 'my_submit';
            break;
    }
}


Then the secondary submit function:

function my_submit($form, &amp;$form_state) {
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    module_load_include('inc', 'webform', 'includes/webform.components');
    global $user;

    $node = $form['#node'];
    $sid = $form_state['values']['details']['sid'] ? (int) $form_state['values']['details']['sid'] : NULL;
    $submission = webform_get_submission($node-&gt;webform['nid'], $sid, TRUE);

    //Build the custom email array for the webform email handler
    $email = array(
     array(
      'nid' =&gt; $node-&gt;webform['nid']
      ,'eid' =&gt; count($node-&gt;webform['emails']) + 1
      ,'email' =&gt; $form_state['values']['submitted'][3]
      ,'subject' =&gt; 'Your Custom Subject Line!'
      ,'from_name' =&gt; 'default'
      ,'from_address' =&gt; 'default'
      ,'template' =&gt; '&lt;table "style=width:100%"&gt;
              &lt;tr&gt;&lt;td&gt;Hello '.$form_state['values']['submitted'][1].',&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;b&gt;More HTML goes here&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'
      ,'html' =&gt; 1
      )
     );
     webform_submission_send_mail($node, $submission, $email);
 }


You could also probably just use the drupal_mail function to send the email in your custom submit function.  I just haven't tested that option.  

For further info, take a look at  webform_client_form_submit and webform_submission_send_mail