How to Send User Email When Registration is Approved

Overview

Would you like to send an email when a user’s registration is approved or even unapproved? WPForms makes it easy to send out an approval email or a “welcome” email as well as sending out a notification of being unapproved. We’ll walk you through how to use PHP to send out these notifications.

In the WPForms User Registration addon settings, you can choose to manually approve anyone who registers to your WordPress site.

Enable manual activation on the user registration form

With the Manual Approval option enabled, an email will automatically be sent to let them know their registration still needs to be activated by a site administrator.

If you’d like, this email’s content can also be customized.

Implementation Options

To enable the approved or unapproved email, choose which code snippet below you’d like to use and then add the snippet to your site.

Any notification email customizations you’ve set up for other form emails will be applied to this email as well.

User email notification when approved

Be sure to adjust this code as well for your use (items marked with an asterisk * must be changed):

  • Email Subject
  • Email Message
  • From Name *
  • From Email Address *

Additionally, the $message value can include HTML tags as well.

/**
 * WPForms User Registration: Send user email when registration is approved.
 * 
 * @link https://wpforms.com/developers/send-user-email-when-registration-is-approved/
 *
 * @param int $user_id
 */
function wpf_dev_approval_email( $user_id ) {
     
    $user = get_userdata( $user_id );
 
    $subject = 'User Account Approved';
    $message = 'Hi There! We just wanted to let you know your user account on example.com has been approved.';
 
    // Send email with the WPForms email template.
    $emails = new WPForms_WP_Emails;
    $emails->__set( 'from_name', 'John Doe' );
    $emails->__set( 'from_address', 'john@example.com' ); // If using SMTP, be sure to use that email address here.
    $emails->send( $user->user_email, $subject, $message );
}
add_action( 'wpforms_user_approve', 'wpf_dev_approval_email' );

Notification of email when user is approved

User email notification when unapproved

Alternatively, you can add this PHP snippet to send an email notification to the user if the request was denied or unapproved.

/**
 * WPForms User Registration: Send user email when registration is NOT approved.
 * 
 * @link https://wpforms.com/developers/send-user-email-when-registration-is-approved/
 * 
 * @param int $user_id
 */
function wpf_dev_unapproval_email( $user_id ) {
     
    $user = get_userdata( $user_id );
 
    $subject = 'User Account Not Approved';
    $message = 'Hi There! We just wanted to let you know that your user account on example.com, unfortunately, wasn't approved.';
 
    // Send email with the WPForms email template.
    $emails = new WPForms_WP_Emails;
    $emails->__set( 'from_name', 'John Doe' );
    $emails->__set( 'from_address', 'john@example.com' ); // If using SMTP, be sure to use that email address here.
    $emails->send( $user->user_email, $subject, $message );
}
add_action( 'wpforms_user_unapprove', 'wpf_dev_unapproval_email' );

Notification of email when user is denied or unapproved

And that’s it! Using these PHP snippets you can easily send out notifications when approving or denying the user’s access. Would you like to learn how to change the validation messages on the user registration form? Try out the tutorial on How to Change Validation Messages for User Registration Addon.

Action Reference: wpforms_user_approve and wpforms_user_unapprove