Elementor form email logic

User
elementor form widget send email to based on dropdown selection
Assistant
To **send an email to different recipients based on a dropdown selection in an Elementor Form widget**, you can use a bit of custom PHP with Elementor Pro’s built-in **“Actions After Submit” → Webhook** or a **custom `functions.php` hook**. Here’s how you can set it up:

### ✅ Use Case Example:
Suppose your form has a dropdown labeled "Department" with these options:

– Sales
– Support
– Billing

And based on the selected department, you want to send the form submission to a different email address.

## 🛠 Method 1: Using `functions.php` Hook (Recommended)

### Step 1: Add a Dropdown Field
In Elementor form:
– Label: `Department`
– Type: `Select`
– Options:

Sales
  Support
  Billing

Give it a shortcode name like: `department`.

### Step 2: Add This Code to `functions.php` (or in a Code Snippets plugin)

add_action('elementor_pro/forms/new_record', function($record, $handler) {
    // Make sure it's the right form
    $form_name = $record->get_form_settings('form_name');
    if ('Contact Form' !== $form_name) {
        return;
    }

    // Get submitted fields
    $fields = $record->get('fields');
    $department = $fields['department']['value']; // Match this with your field shortcode

    // Define recipient based on selection
    $email_map = [
        'Sales'   => 'sales@example.com',
        'Support' => 'support@example.com',
        'Billing' => 'billing@example.com',
    ];

    // Default fallback
    $to = $email_map[$department] ?? 'default@example.com';

    // Set new recipient email
    $handler->add_email( 'email', [
        'to' => $to,
        'subject' => 'New Form Submission',
        'message' => 'Form submission from ' . $department,
    ]);
}, 10, 2);

> Replace `'Contact Form'` with the actual **Form Name** you set in the Elementor editor.
> And adjust the `'message'` or other email fields as needed.

## 🧪 Alternative: Using Webhook + Zapier/Make (No-code approach)
1. Add a **Webhook** action to your form.
2. Send all form data to Zapier/Make.
3. Use a conditional step there to forward the email to the correct address.

Do you want me to tailor this code specifically for your form setup (like field names or specific departments)?

User
How to get elementor form name
Assistant
To get the **Elementor form name**, follow these steps:

### ✅ Method 1: Check in the Elementor Editor
1. **Edit the page** with Elementor.
2. Click on the **Form Widget**.
3. In the **left panel**, scroll down to the **"Additional Options"** section.
4. Look for the **“Form Name”** field.
– If it's empty, set a unique name like `Contact Form` or `Support Request`.

📌 This is the name used in the hook:

$form_name = $record->get_form_settings('form_name');

### ✅ Method 2: Use This Temporary Debug Snippet to Log the Form Name
If you're not sure what the form name is and don’t want to open Elementor:

add_action('elementor_pro/forms/new_record', function($record, $handler) {
    error_log('Form Name: ' . $record->get_form_settings('form_name'));
}, 10, 2);

– Then submit the form once.
– Check your **`debug.log`** file under `wp-content` or enable debugging like this in `wp-config.php`:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

Let me know your form name or paste the options you use in the dropdown, and I’ll help generate the exact PHP code.

User
s:311:"a:8:{s:13:"field_17e133f";s:9:"oldenburg";s:13:"field_06b9e7a";s:4:"frau";s:4:"name";s:9:"fsagagfas";s:13:"field_ee0aae2";s:6:"fgagag";s:5:"email";s:19:"test2015j@gmail.com";s:7:"message";s:8:"fsagfags";s:13:"field_4795f5b";s:0:"";s:12:"formCheckbox";s:51:"Zustimmung zur Datenverarbeitung, Datenschutz, etc.";}";
how to send email for oldenburg
Assistant
Thanks! The serialized string you've posted is the raw submission data from an Elementor form. You're particularly interested in this part:

s:13:"field_17e133f";s:9:"oldenburg";

This means the submitted value for `field_17e133f` is `"oldenburg"` — likely from a dropdown or hidden field.

### ✅ To send email **only when 'oldenburg' is selected**, use this snippet:

add_action('elementor_pro/forms/new_record', function($record, $handler) {
    // Optional: Check form name if needed
    $form_name = $record->get_form_settings('form_name');
    if ('Your Form Name' !== $form_name) {
        return;
    }

    // Get fields
    $fields = $record->get('fields');

    // Replace 'field_17e133f' with the actual shortcode/key name of the dropdown
    $location = $fields['field_17e133f']['value'] ?? '';

    if (strtolower($location) === 'oldenburg') {
        $handler->add_email('email', [
            'to' => 'oldenburg@example.com', // change to the actual recipient
            'subject' => 'New Submission for Oldenburg',
            'message' => 'Someone selected Oldenburg in the form.',
        ]);
    }
}, 10, 2);

### 🔍 How to get the actual field **shortcode** for `field_17e133f`
In Elementor form:
1. Edit the form widget.
2. Click on the field that corresponds to `"Oldenburg"` (probably a dropdown or select field).
3. Look for the **“Shortcode”** or **“ID”** under **Advanced > Field ID**.
4. Replace `field_17e133f` with that ID in the code above.

Let me know if you want to route multiple dropdown values to different email addresses (e.g., `oldenburg@example.com`, `berlin@example.com`, etc.) — I can help you set that up too.

Leave a Comment

Your email address will not be published. Required fields are marked *