2017-04-21 30 views
1

我有一個wordpress網站已經安裝了EasySMTP插件。Wordpress Cron phpmailerexception

我有一個真正的cron任務,我有無效的wp模擬cron。

我的cron正在運行,但是在裏面我想發送郵件並且不工作。

在我的日誌,我看到:

[20-Apr-2017 14:46:02 UTC] PHP Fatal error: Uncaught exception 'phpmailerException' with message 'Invalid address: (setFrom) [email protected][domain]' in /home/user/public_html/wp-includes/class-phpmailer.php:1023 
Stack trace: 
#0 /home/user/public_html/wp-includes/pluggable.php(352): PHPMailer->setFrom('[email protected][domain...', 'WordPress', false) 
#1 /home/user/public_html/wp-content/plugins/innovation-factory/includes/php/functions.php(350): wp_mail('[email protected]', 'Tienes 1 ideas ...', '\n\t\t<html>\n\t\t<bo...', Array) 
#2 /home/user/public_html/wp-content/plugins/innovation-factory/innovation-factory.php(301): enviarNotificacion('[email protected]', 'Tienes 1 ideas ...', NULL, Array, '\n\t\t<html>\n\t\t<bo...') 
#3 [internal function]: do_this_hourly() 
#4 /home/user/public_html/wp-includes/class-wp-hook.php(298): call_user_func_array('do_this_hourly', Array) 
#5 /home/user/public_html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array) 
#6 /home/des in /home/user/public_html/wp-includes/class-phpmailer.php on line 1023 

Obviusly我有其他SMTP配置EasySMTP。事實上,我有一個smtp託管在其他域名與其他域名不同的其他服務器。

如果我從cron中調用do_this_hourly()函數,它會正確發送電子郵件。我需要做一些不同的郵件在cron任務?也許,該wp-cron.php不加載EasySMTP呢?

我cron是編程用這個命令:

php /home/user/public_html/wp-cron.php 

謝謝!

回答

0

$ _SER 問題是,當通過crontab執行時,php沒有獲得$ _SERVER ['SERVER_NAME']。這就是phpmailer拋出異常的原因。

我通過在crontab中手動傳遞變量來解決它。 F.e:

*/15 * * * * export SERVER_NAME="server.domain.name" && php /var/www/clients/client2/web8/web/wp-base/wp-cron.php 

這個問題的詳細描述可以在這裏找到https://www.ask-sheldon.com/wordpress-cron-using-wp_mail-function/

+0

我終於解決了這個問題,在我的wp安裝的根目錄下創建cron.php文件,並在wordpress之外完成我的工作。這不是一個好方法,但是我能做到的唯一工作。 – msolla