How to send email notifications to the current logged in user

Created by Phil Kurth, Modified on Tue, 28 Jun, 2022 at 5:33 PM by Phil Kurth

If you need to override the email address to send notifications to the current logged in user, you may do so using the af/form/email/recipient filter.

add_filter( 'af/form/email/recipient', function ( $recipient, $email, $form, $fields ) {
  // Make sure we are handling the right form. If not, return the set value.
  if ( $form['key'] !== 'YOUR_FORM_KEY_HERE' ) {
    return $recipient;
  }

  // Get the current user. If found, return email.
  if ( $user = wp_get_current_user() ) {
    return $user->user_email;
  }

  return $recipient;
}, 10, 4 );

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article