Halloween Sale 15% off Ends in See the plans
PHP

Follow-Up Email a Few Days After Sign-Up

Sends new users a second, friendly email a few days after they register, with tips or links to get started, scheduled automatically with WP-Cron.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_followup = array(
    'days'    => 3,
    'subject' => 'Getting the most out of {site}',
    'message' => "Hi {name},\n\nThanks for joining {site} a few days ago! Here are a few things to try next:\n\n• Complete your profile\n• Browse our latest articles\n• Reply to this email if you have any questions\n\nSee you soon!",
);

add_action( 'user_register', function ( $user_id ) use ( $wpide_followup ) {
    wp_schedule_single_event( time() + $wpide_followup['days'] * DAY_IN_SECONDS, 'wpide_followup_email', array( (int) $user_id ) );
} );

add_action( 'wpide_followup_email', function ( $user_id = 0 ) use ( $wpide_followup ) {
    $user = get_userdata( (int) $user_id );

    if ( ! $user || ! is_email( $user->user_email ) ) {
        return;
    }

    $site    = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
    $replace = array( '{name}' => $user->first_name ? $user->first_name : $user->display_name, '{site}' => $site );

    wp_mail( $user->user_email, strtr( $wpide_followup['subject'], $replace ), strtr( $wpide_followup['message'], $replace ) );
} );

Notes

Edit the delay, subject and message at the top ({name} and {site} are replaced); the email is skipped if the account has been deleted meanwhile.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.