Wordpress Cron phpmailerexception



我有一个已安装easysmtp插件的WordPress网站。

我有一个真正的cron任务,我有不活跃的WP模拟cron。

我的cron在运行,但是里面我想发送一封邮件,并且不起作用。

在我的日志中,我看到了:

[20-Apr-2017 14:46:02 UTC] PHP Fatal error:  Uncaught exception 'phpmailerException' with message 'Invalid address:  (setFrom) wordpress@[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('wordpress@[domain...', 'WordPress', false)
#1 /home/user/public_html/wp-content/plugins/innovation-factory/includes/php/functions.php(350): wp_mail('msolla@domain...', 'Tienes 1 ideas ...', 'ntt<html>ntt<bo...', Array)
#2 /home/user/public_html/wp-content/plugins/innovation-factory/innovation-factory.php(301): enviarNotificacion('msolla@domain...', 'Tienes 1 ideas ...', NULL, Array, 'ntt<html>ntt<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

casvius我在easysmtp中还有其他SMTP配置。实际上,我在其他服务器中托管了一个与de web页面域不同的服务器。

如果我从cron中调用do_this_hourly((函数,它将正确发送电子邮件。我需要做一些不同的事情来邮寄cron任务吗?也许wp-cron.php还没有加载easysmtp?

我的cron用此命令编程:

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

谢谢!

这似乎来自以下事实:$ _server ['server_name']在使用crontab,cli或其他某些命令行脚本发送cron时未设置邮件。

$_SERVER['SERVER_NAME']发出通知, $sitename是一个空字符串, $from_email只是'wordpress@'。

WordPress至少给您一个机会在尝试发送之前设置$from_email,在这种情况下,我添加了一个似乎对我有用的过滤器。

add_filter( 'wp_mail_from', function( $from_email ) {
    // Domain ends with an @. Append the domain from the site url.
    if ( substr( $from_email, -1 ) === '@' ) {
        // Trim protocol, double forward slash, preceeding www, port, and remaind of request uri.
        $from_email .= preg_replace( '#^(?:[hftps]*:)?//(?:www.)?|[:/?].*$#i', '', get_site_url() );
    }
    return $from_email;
} );

$ _ 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/。

相关内容

  • 没有找到相关文章

最新更新