• Hi, I’m aware the question I’m about to ask is not really related to FIXING WORDPRESS
    I Just wanted to ask a general favour.
    I’m working on something and wanted that after a specific number of years, a user would receive an email notification. I want to try out this code, but want to confirm first if it will be effective.

    function the_dramatist_handle_scheduled_mail( $arg_1 = '', $arg_2 = [] ) {
        wp_schedule_single_event(
            // Here time() is the time when this is firing and 31536000s = 8760h = 365d
            time() + 31536000,
            // Declaring a hook at this point. You can hook any function to this point which you want to fire after three days of any base event.
            'the_dramatist_send_email_after_three_hundred_and_sixty_five_days',
            // You can add number of arguments to the hook also.
            [ $arg_1, $arg_2 ]
        );
        return true;
    
    }
    
    add_action( 'the_dramatist_send_email_after_three_hundred_and_sixty_five_days', 'the_dramatist_send_email_after_three_hundred_and_sixty_five_days_function', 10, 2 );
    
    function the_dramatist_send_email_after_three_hundred_and_sixty_five_days_function( $arg_1, $args_2 ) {
    
        $to = '[email protected]';
        $user = get_user_by( 'email', $to );
        if ( 1 === get_user_meta( $user->ID, 'after_three_hundred_and_sixty_five_days_email', true ) ) {
            return false;
        }
    
        $subject = 'E-mail Title!';
        $body = 'E-mail body';
        $headers = array('Content-Type: text/html; charset=UTF-8');
    
        $mail_sent = wp_mail( $to, $subject, $body, $headers );
        // After sending the email to every person I prefer to put a record.
        if ( $mail_sent ) {
            update_user_meta( $user->ID, 'after_three_hundred_and_sixty_five_days_email', 1 );
    
            return true;
        }
    }

    Thanks in anticipation of your response!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto Send Email to Users After Number of Days’ is closed to new replies.