wordpresscrondreamhost

Unable to run dreamhost cron job to send emails on wordpress site


These are the steps that I followed to set up my CRON :

  1. define('DISABLE_WP_CRON', true); added in wp-config.php file
  2. Installed WP Control and Added a Hook lead_mail_gun.
  3. Added following code in my code snippets.
add_action( 'lead_mail_gun', 'cron_test_function' );

function cron_test_function() {
    $email = 'my-mail-id';
    $headers = 'From: '. $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n";

    wp_mail('my-mail-id', 'WP Crontrol', 'WP Crontrol rocks!', $headers);
}
  1. I can see my funciton in the list of CRON events list.
  2. Also I can see The DISABLE_WP_CRON constant is set to true. WP-Cron spawning is disabled. which confirms that default CRON is off
  3. In my dreamhost I added a CRON Job with the following command /usr/local/php72/bin/php /home/path_to_my_cron_file/wp-cron.php running every 10 mins.

I am getting no emails. What can be the cause of emails not being sent ?

I have tested that I can send emails though my server.


Solution

  • So the fix was simple.

    Use the following in the command section of CRON.

    curl https://www.example.com/wp-cron.php