Send Approval Email when user registered
-
Hi,
I’m creating a website for a client where the user fills out a form (contact form 7), submit the form, and is redirected to a contract signing page (wp-esignature). I created a custom snippet that registers the user once the form is submitted. The snippet also includes a function that passes the userID to the um()->user()->approve() function. This function triggers the approved email.
The account username and email are correct but the set password is not. Instead of displaying the reset password hash it displays {password_reset_link} which redirects the user to a 404 page.
I’m using wpmail SMTP and Brevo to send emails. I excluded the password reset page from the cache. I’m assuming it has something to do with my code logic.
function custom_process_form_submission( $contact_form ) { // Replace $contact_form_id with the ID of your Contact Form 7 form $contact_form = WPCF7_ContactForm::get_current(); $contact_form_id = $contact_form->id; // Example ID, replace with your actual form ID // Check if the submitted form is the desired Contact Form 7 form if ( $contact_form->id() == $contact_form_id ) { $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $posted_data = $submission->get_posted_data(); // Extract form data $first_name = sanitize_text_field( $posted_data['your-name'] ); $last_name = sanitize_text_field( $posted_data['last-name'] ); $email = sanitize_email( $posted_data['your-email'] ); // Generate username (customize as needed) $username = strtolower( $first_name . '_' . $last_name ); // Check if the username already exists and handle uniqueness if ( username_exists( $username ) ) { $username .= '_' . uniqid(); } // Generate a random password $password = wp_generate_password(); // Create the user $user_id = wp_create_user( $username, $password, $email ); if ( ! is_wp_error( $user_id ) ) { // The user registration is successful, send approval email send_approval_email_after_registration( $user_id, array( 'form_data' => $posted_data ) ); } else { // Handle error gracefully, perhaps by displaying a user-friendly message error_log( 'User account creation failed: ' . $user_id->get_error_message() ); return; } } } } function send_approval_email_after_registration( $user_id, $args ) { // Check if the user ID is valid if ( ! empty( $user_id ) ) { // Trigger approval email from Ultimate Member um()->user()->approve( $user_id ); // Log a message to indicate that the approval email is sent error_log( 'Approval email sent for user ID: ' . $user_id ); } }
- The topic ‘Send Approval Email when user registered’ is closed to new replies.