IMPLEMENTED: Send second email from form

Does anyone have a custom script to send a second email from Bricks forms?

At the moment, you can only send the one.

I’d like one to go to the site admin and one to confirm what was submitted to the sender.

2 Likes

Please find a starting example here: Bricks: Form custom action to trigger second email · GitHub

1 Like

Whats with all the extra code? Defeats the point of an element builder!

Would love to see the ability to add a second Email item under Actions and a second Email item appear in the menu.
Also what does the Custom item do? No new Custom menu item appears so not clear how to use it.

1 Like

I think adding custom code is a backwards solution. What happens when the 2nd email is added as an action (which it should be) — do we then need to go through every site and remove the script to add the new action?

@Ross Customisable form-submit confirmation emails are currently not natively built into Bricks. But I have just approved it as a feature request over here: https://bricksbuilder.io/ideas/#3422 and added this forum thread to the feature request. I will update you once this feature progresses. Thank you!

1 Like

+10000 for this one :slight_smile:

In the meantime, here is my script:

add_action( 'bricks/form/custom_action', function( $form ) {

    $fields = $form->get_settings()['fields'];
    $values = $form->get_fields();
    foreach ( $fields as $field ) {
        if ( $field['label'] == 'Email' ) {
            $email = $values['form-field-' . $field['id']];
        } elseif ( $field['label'] == 'Nom' ) {
            $name = $values['form-field-' . $field['id']];
        }
    }

    $subject = "Votre message blablablabla";
    $message = "Bonjour " . $name . ",\n\nNous avons bien reçu votre message et reviendrons vers vous dans les meilleurs délais.\n\nCordialement,\nBlablablablabla";

    $result = wp_mail( $email, $subject, $message );
    
    $form->set_result([
        'action' => 'my_custom_action',
        'type'    => $result ? 'success' : 'danger',
        'message' => esc_html__( "Un problème est survenu pendant l'envoi du mail de confirmation.", 'bricks' )
    ]);

}, 10, 1 );

Should be pretty self explanatory.
Just replace the field labels in the loop to get the information you need.

(I use a loop here to get the correspondances between form labels and submitted values.)

Please note that you can already have the form send multiple emails to multiple addresses (tested in Bricks 1.6). “Send to email address” should be set to “Custom email address”. Then in the “Send to custom email address field”, just enter multiple email addresses separated by a comma and a space (e.g., test@example.com, test2@example.com). You can also use the ID of an email field in the form to populate the user’s email address in this field (e.g., test@example.com, {{email-field-id}}). I think the best solution is to place the user’s email address in the to-field, and then put your email address (or whoever should be receiving the submissions) in the BCC-field, so that you don’t reveal the address the forms are being revealed to to the user.

Example of my suggested usage.

Screenshot_20221209_173815

Also see Form Element – Bricks Academy

Sure, but we are talking about a second email with different content, for instance a confirmation email for visitor.

I see. I misunderstood the requirements then.

Hi guys,
We’ve added confirmation email settings in Bricks 1.7.2, now available as a one-click update in your WordPress Dashboard.

Please let us know if you are experiencing any issues.

Best regards,
timmse

1 Like

where was this added? so I would like to send two e-mails, one to me (when the form is completed) and the other with different content to the client, thanking e.g.