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]';
break;
case 'US':
$recipient = '[email protected]';
break;
default:
$recipient = '[email protected]';
break;
}
$message['to_mail'] = $recipient;
parent::sendMessage($message);
}
}