1

I have a very simple function and hook registration in my functions.php, like this:

function do_this_thingy(){
   // I am sending myself some simple admin report mails, tested & works
}
add_action( 'mail_event_hook', 'do_this_thingy');

Then, in a page template I have a row:

wp_schedule_single_event( time() + 600, 'mail_event_hook' );
// expected: to receive message in ten minutes time. Result: no message :(

What might be going wrong?

Edit: Answers to questions:

  1. Is this on a local server? No, this is a live WP site of mine.
  2. How do I know that emails can be sent in the first place? The code that I use to send emails works perfectly if I simply run it from functions.php or another .php file on the server. I receive the email every time I try.
  3. Am I sure the CRON job fired? I have the plugin WP Crontrol and it shows no scheduled task / cron job. I assume thus that the answer is no.
  4. Are there PHP errors in the logs? I can take a look at this with debug logging enabled later today. Will update.
  • 1
    Is this on a local server? How are you confirming that your server is capable of sending emails? Are you sure the cron job fired? Or that it fired but the email part is what failed? Is there a message in your PHP error log? Please edit your question with those details, even if the answer is that you don't know – Tom J Nowell Dec 2 '19 at 16:08
  • @TomJNowell Thank you for the questions. I added the things you asked for. – Jussi Dec 4 '19 at 10:47
0

Solved, although in a pretty poor manner.

If I move the scheduler function

wp_schedule_single_event( time() + 600, 'mail_event_hook' ); 

into functions.php it starts working. Not sure why, but this is the curse of self taught developers.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.