Sending a webform to a different email based on country

I can confirm that this work around does seem to work. Whether it's a good way to do it or not is another matter. This webform hook is called after being submitted to the db but I don't think it matters where it's done. It basically uses the country codes generated by the country select box to define the email used

function MODULE_NAME_webform_submission_insert($node, $submission) {

if ($node->nid == WEBFORM_NODE) {

//GET $subject and body and whatever else is desired using $submission->data[FIELD_NUMBER]['value'][0]

if ($submission->data[FIELD_NUMBER]['value'][0] === "GB") {
    $email = '';
$module = 'MODULE_NAME';
  $key = 'key';
  $language = language_default();
  $params = array();
  $from = NULL;
  $send = TRUE;
  $message = drupal_mail($module, $key, $email, $language, $params, $from, $send);

      $message['subject'] = $subject;
      $message['body'] = array();
      $message['body'][] = $body;

      // Retrieve the responsible implementation for this message.
      $system = drupal_mail_system($module, $key);
      // Format the message body.
      $message = $system->format($message);

      // Send e-mail.
      $message['result'] = $system->mail($message);



Add new comment