• Resolved Tuuuukka


    It’s easy to add a recipient for a notification with af/form/email/recipient, but what if I want to add that recipient for a certain notification?

    Let’s say I need to send two different confirmation emails after the submit: one for the sender and one for the owner/seller who’s information is saved in the post (I have this form at the end of every post in category X). So that’s two different emails that don’t have the same exact content.

    The email address for the sender is taken from the filled form. But the address of the owner/seller is saved in the post in an ACF field. With af/form/email/recipient I can get that saved address and add it to the list of recipients, but now I’d need to select that certain email notification I want to send to this address. Is that possible?

    I can send the same email to both, but that’s not ideal nor is it intentional to have the sender and the owner see each other email addresses.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tuuuukka


    A little update on this. The only way I have managed to get this to work is by adding an email field on the form, prefilling it with the sellers address, hiding the rendered field with CSS and disabling it with JS.. I then created the notification and used this field’s value as the recipient.

    But this is waaaaay too insecure and hacky. Just by looking at the source code you can see the actual email address and by disabling JS on your browser you can put whatever address you want in that field. No good.

    Preventing the rendering of this field on front-end with $args makes it unavailable as the source of a recipient’s email address.

    And of course I tried creating PHP functions and using actions like af/email/before_send but no luck. I don’t even get what that af/email/before_send is supposed to be used for, seems like it’s not good for anything really..?

    Thread Starter Tuuuukka


    I solved the validation for the address field on the form by adding a hidden field that contains the id of the post/page the form is displayed on. validate_form() then picks up that id, uses that id to load the ACF field containing the address and compares it to the address that’s on the form. Thus, if someone “hacks” the code and changes the address on the form field (that’s hidden with CSS and disabled with JS) the form throws an error.

    But this is still pretty hacky and anyone can see the email address by looking at the source code.

    What would be nice would be to have an id for every email notification. Then with af/form/email/recipient you could add the address AND set the id of the email notification you want to send, i.e:

    function filter_email_recipient( .... ) {
        $email['recipient'] = 'john@doe.com';
        $email['id'] = 'XX';
        return $email;
    • This reply was modified 5 years, 8 months ago by Tuuuukka.
    Plugin Author fabianlindfors


    Hi! I see you’ve done quite a bit of testing yourself, great!

    There is one way to identify specific emails and that is the required “Name” field set when adding an email. You can access this field in af/form/email/recipient as the second parameter is $email, an array representing the specific email notification.

    Here’s how you could check if you were to name your email “Admin notification”:

    function filter_email_recipient( $recipient, $email ) {
      if ( 'Admin notification' == $email['name'] ) {
        return 'overriden-recipient@domain.com';
      return $recipient;
    add_filter( 'af/form/email/recipient', 'filter_email_recipient', 10, 2 );

    Hope this helps! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding recipient to a certain email notification dynamically’ is closed to new replies.