WP_Mail not running inside Cron

Question

Wp_Mail function is not running when scheduled in a cron function. I have added the following function:

add_filter( 'cron_schedules', 'isa_add_every_one_minutes' );
function isa_add_every_one_minutes( $schedules ) {
    $schedules['every_sixty_seconds'] = array(
            'interval'  => 60,
            'display'   => __( 'Every 1 Minutes', 'textdomain' )
    );
    return $schedules;
}

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'isa_add_every_one_minutes' ) ) {
    wp_schedule_event( time(), 'every_sixty_seconds', 'isa_add_every_one_minutes' );
}

// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_one_minutes', 'only_debug_admin' );


function only_debug_admin(){
    $message = "Test message";

wp_mail( 'email@example.com', $message, $message );

update_option('default_role','customer');   
    }

When I run the cron manually via wp-control plugin, I receive a mail and wp-mail works fine. However, when the cron job is run. To debug, I add this line below the mail function:

update_option('default_role','customer'); 

I set the default role to subscriber in wordpress settings. On cron run, the setting gets updated to ‘customer’ but the mail is not received. On manually running the function, the mail is received. Any idea why this is happening?

0
, dc09 2 years 2019-12-03T15:33:24-05:00 0 Answers 91 views 0

Leave an answer

Browse
Browse