1. Home
  2. Snippets
  3. Send user email when registration is approved

Send user email when registration is approved

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

For extra guidance, please see WPBeginner's tutorial on adding custom code.

Dismiss

In the WPForms User Registration addon settings, you can choose to manually approve any users who register to your WordPress site.

When this is enabled, the user will automatically receive an email to let them know their registration still needs to be activated by a site administrator. If you’d like, this email’s content can be customized.

It is also possible to send users an email based on the approval of their registration by adding the code snippets below to your site. Then, be sure to adjust this code 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 if you’d like.

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

Send user email when registration is approved

/**
 * WPForms User Registration: 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' );

Email when user registration is approved

Send user email when registration is unapproved

/**
 * WPForms User Registration: Send user email when registration is NOT 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' );

Updated on June 12, 2019

Was this article helpful?