views:

124

answers:

1

drupal 6 web form module allows a user to specify a "to" email address. but how can i change that "to" email adress programmatically.

for example: i have some nodes in the drupal 6 system, each node has an email address, when a person accesses that node (page), programm put that node's email address in a session variable, then when the person click a link on the node, the link will shows a web form.

at this point, when the person clicked submit button, i want the web form send a email to the node's email address (email address saved in a session variable).

thanks.

+1  A: 

You need to use the mail_alter hook and change the value of $message['headers']['to'].

function myModule_mail_alter(&$message) 
{
  // Don't forget to check if the mail is actually a webform submission
  if ( ($message['id'] == 'webform_submission')  )
  {
        $message['headers']['to']   = $myMail;
  }
}

More info

Januz
notice: in webform module edit page, you must supply a default "to" email address, otherwise _mail_alter function will not be called.
anru