In Drupal 7, Webform module have the ability to map different emails against webform component's options so that the webform notification could be sent to different emails depending on a user selection.

webform email handler settings

In Drupal 8, Webform was ported and its email submission settings pretty basic so I decided to use YAML Form. However, YAML Form email handler have the ability to either have a custom emails separated by comma or a value from the component.

enter image description here

Is there a way to have component email mapping functionality?

2 Answers 2


The feature has been added to the latest dev release of Webform-8.x-5.x.

@see Issue #2854021 by jrockowitz: Send email based on element options selection


Currently the functionality is not inbuilt to web forms UI but it can still be done with a custom module.

Following the webform recpie on handlers you can create a custom email handler like so:

Folder/File structure:

  • ModuleName
    • src
      • Plugin
      • WebformHandler
        • MODULENAMEWebformHandler.php
    • MODULENAME.info.yml

Content example for MODULENAMEWebformHandler.php

namespace Drupal\MODULENAME\Plugin\WebformHandler;
use Drupal\Core\Url;
use Drupal\webform\Plugin\WebformHandler\EmailWebformHandler;

* Emails a webform submission.
* @WebformHandler(
*   id = "test_email",
*   label = @Translation("New Email"),
*   category = @Translation("Notification"),
*   description = @Translation("Send email depending on dropdown value"),
*   cardinality = \Drupal\webform\WebformHandlerInterface::CARDINALITY_UNLIMITED,
*   results = \Drupal\webform\WebformHandlerInterface::RESULTS_PROCESSED,
* )
class MODULENAMEWebformHandler extends EmailWebformHandler {

  public function sendMessage(array $message) {

    $form_data = $message['webform_submission']->getData('dropdown_id');

    switch($form_data) {

     case 'APAC':
       $recipient = '[email protected]';

     case 'US':
       $recipient = '[email protected]';

       $recipient = '[email protected]';

    $message['to_mail'] = $recipient;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.