Using different E-Mails in Form Builder for EmailFinisher

Hello!

I have created an Form with the Neos Form Builder. Everything is working so far, but I ran into an issue.

I have an dropdown with different categories. Based on the selected category, it should send the E-Mail to an different recipient.

For example:
I have a dropdown [“Marketing”, “Sales”, “Service”]
if “Service” is selected, it should send an E-Mail to service@example.com. If “Marketing” is selected, it should send an E-Mail to marketing@example.com.

Has anybody an idea how to achieve this?
Thanks in advance!

Hi Lukas,

A common requirement, but unfortunately the built-in EmailFinisher doesn’t support it.
Two options I see:

  1. Extend the EmailFinisher so that it does support custom recipients defined in a separate form value and create a Pull Request against https://github.com/neos/form/
  2. Create a custom EmailFinisher that works exactly like you need it

A little dummy/example code to get you started:

$fieldValue = ObjectAccess::getPropertyPath($finisherContext->getFormValues(), $this->options['recipientMappingField']);
if ($fieldValue !== null && array_key_exists($fieldValue, $this->options['recipientMapping'])) {
    $recipient = $this->options['recipientMapping'][$fieldValue];
}

With that you’ll need to specify two options. recipientMappingField (the form element identifier of your category selector) and recipientMapping (an associative array with “” => “” mapping