I operate some servers which have a few WordPress websites on them. I was having some issues with the cron jobs being triggered too often or not enough so I replaced all of them with crontab entries, one or more for each site as appropriate.

Most documentation I have seen uses curl or wget and dumps the output to /dev/null so I wanted to use PHP directly since it is a PHP file after all and I would then capture any error output that way.

This accomplishes the tasks I want to fine however now every few weeks I get several of the following messages:

PHP Fatal error:  Uncaught exception 'phpmailerException' with message 'Invalid address:  (setFrom) wordpress@' in /path/to/website/public_html/wp-includes/class-phpmailer.php:1023
Stack trace:
#0 /path/to/website/public_html/wp-includes/pluggable.php(352): PHPMailer->setFrom('wordpress@', 'WordPress', false)
#1 /path/to/website/public_html/wp-admin/includes/class-wp-automatic-updater.php(769): wp_mail('<adminemail>', '<subject>', '<message>', '')
#2 /path/to/website/public_html/wp-admin/includes/class-wp-automatic-updater.php(501): WP_Automatic_Updater->send_email('success', Object(stdClass))
#3 /path/to/website/public_html/wp-admin/includes/class-wp-automatic-updater.php(470): WP_Automatic_Updater->after_core_update(Object(stdClass))
#4 /path/to/website/public_html/wp-includes/update.php(532): WP_Automatic_Updater->run()
#5 [internal function]: wp_maybe_auto_update( in /path/to/website/public_html/wp-includes/class-phpmailer.php on line 1023

As I understand it, wp-cron.php has successfully caused the WordPress to be updated to the next version and wanted to email the site administrator about it.

Examining the code of wp-includes/pluggable.php I can see that it tries to generate a "from email address" using the contents of $_SERVER which obviously aren't there as it is being run from the command line and not via the web server.

I feel that using PHP directly from the command line is more efficient than invoking curl or wget but also there is no error checking present to verify a "from email address" has been generated correctly.

My question is, which of the following is true (or are both?) and what should I do about it:

1) wp-cron.php should ONLY be called using wget or curl and there is error checking missing that would force the administrator to avoid cli

2) wp-includes/pluggable.php is missing email validation checking

I can see there has been hefty debate about how an email address should be generated but am keen to not dig up resolved arguments and would appreciate a direction in resolving this issue.

  • Are you ok with hooking into apply_filters( 'wp_mail_from', $from_email ); and within the filter callback set your from email address? – czerspalace Apr 20 '17 at 21:54
  • That would be a good solution, the websites have custom themes so adding more code wouldn't be an issue. My question is more about something being missing within WordPress itself though as one would hope the code would be more resilient. – William Power Apr 21 '17 at 8:10
  • Have you tried using WP CLI to run the cron? Your email issue seems unrelated to how cron is triggered – Tom J Nowell May 17 at 11:12

Your Answer

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

Browse other questions tagged or ask your own question.