Send Email Notification to Multiples Addresses

By: Roger Berges | Asked: 02/06/2023
ForumsCategory: General questionsSend Email Notification to Multiples Addresses
Roger Berges asked 2 years ago

Hi all! I have three forms, one for vendor registration, another for buyer registration and a RFQ form. The buyer submits a RFQ and the vendors should receive an email notification about it.

I can't seem to get a good solution on how to get the 20+ vendors emails to the BCC Send Email action. One thing that comes to mind is to do a GET request and load them into a hidden field, then just set the BCC to that field, but that request will show on the network tab and anyone with the right knowledge would extract all the vendors emails from there.

If I can't do this using only formidable forms, what integration would you recommend (zapier, hubspot)? Thanks in advance! RBC

Bobby Clapp replied 2 years ago

20 emails isn't really a problem for Formidable. A checkbox or list that is multiselect then using a sep=", " would capture them if they come from a form field. Is there more to it that I don't get from this?

Martin Splinter replied 2 years ago

uh.. just add the email addresses in the BCC field in form actions?

Victor Font replied 2 years ago

When you add emails manually to a send field, they will remain as part of the action for that form until you physically. A more flexible alternative would be to create your own shortcode that receives the RFQ number as a parameter. This way your BCC list is dynamic and will change automatically for any RFQ and list adjustments such as additions or deletions.

2 Answers
Rob LeVineRob LeVine answered 2 years ago
If you're trying to do what I think, here's a solution I've used many times. In the bcc field of the email action, use a custom shortcode, eg., [my-bcc-list] and then, in the shortcode's PHP, assemble a comma-separated list of email addresses and return that string.
Rob LeVineRob LeVine replied 2 years ago

See? Victor and I agree so we must be right 🙂

Roger Berges replied 2 years ago

Yes! This! I think this is the way, I'll give it a go later on and report back. In my initial comment I failed to mention that the list was going to be dynamic, but this takes that into consideration. Thanks Rob and Victor!

Roger Berges answered 2 years ago
Update: This is working as a charm
function getVendorEmails( $atts ) {
    $users = get_users();
    $emails = array();
    foreach($users as $user){
        if ($user->roles[0] == 'vendor') {
            $emails[] =  $user->user_email;
        }
         }
         return implode( ',', $emails );
}

add_shortcode( 'vendor_emails', 'getVendorEmails' );
Just inserted the [vendor_emails] to the BCC field and that was it. Thanks again!
Victor Font replied 2 years ago

This is good looking code and fit for purpose. If I may make a suggestion, it wouldn't be too hard to turn this into a generalized function that can be used for any WordPress user role. All you would have to do is pass a role parameter and then use the parameter as a variable in place of the string 'vendor' in the if statement. You can learn how to process a parameter in the WordPress Shortcode API documentation. Nice job!

Roger Berges replied 2 years ago

I don't even have to go that far away to get the information about the parameter passing as there is a KB article detailing this right here https://formidableforms.com/knowledgebase/php-examples/#kb-show-display-names-from-a-list-of-user-ids

But since my use case only needs the vendor, this would be enough. I may do it for the knowledge but leave it as is for now.
Thanks!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right