I am using this code in my functions.php which works fine. However, I was wondering if this is the best practice to do so to schedule an event, or if there is a better solution.
if (!wp_next_scheduled('my_task_hook')) {
wp_schedule_event( time(), 'daily', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
wp_mail('[email protected]', 'Test Email', 'Hello, this is a test automatically scheduled email from WordPress.');
}