How do I email a new page password to somebody every month?

First of all, you should wrap your cron into a method:

function cronjob_once_every_month() {
    // Our custom cron interval:
    $schedules['every_month'] = array(
        'interval'  => 1 * MONTH_IN_SECONDS,
        'display'   => 'Once every Month'
    );
}

a) set up an automated email

Then you should schedule an action:

if ( ! wp_next_scheduled( 'cronjob_once_every_month' ) ) {
    wp_schedule_event( time(), 'email_password_every_month', 'cronjob_once_every_month' );
}

Finally, you should hook into an action to fire the cron:

add_action( 'cronjob_once_every_month', 'email_password_every_month' );
function email_password_every_month() {
    wp_mail( $to, $subject, $message, $headers, $attachments );
}

Tip: you should setup SMTP because wp_mail() does not guarantee the email was received by the user.

b) package the code as a plugin and install it?

Please, read the official documentation.

Leave a Comment