从Cron执行自定义php文件,实现Wordpress邮件发送


Executing custom php file from Cron, implementing Wordpress mail send

我正在构建一种自助服务门户网站,需要在wordpress网站上实现它。门户本身,是建立在纯php, jquery, sql等。没有使用Wordpress库,其余的主要站点依赖于。

我已经在网上搜索了,试图找到我需要的东西,但我找不到匹配的。

. .我要做什么?

我需要每X天在X时钟运行一个Cron作业,触发服务器根目录下的一个自定义PHP文件(我们称之为portal_reminder.php),然后使用内置(或插件?)向自定义PHP文件中指定的目标发送电子邮件。

哦,由于服务器托管在使用多主机的serverpark中,我不允许安装任何"外部"程序(sendmail),也不能在终端(cron -e)中创建自定义cronjob。

所以,我需要一个wordpress cron插件来做cron处理,以及wordpress/other来处理电子邮件。

澄清一下,我的想法如下:

Cronjob触发器"portal_remind .php"

门户提醒触发器"mailsender",包括$to, $from, $content (html content)

"mailsender"发送邮件:)

这可能吗?

Cron作业可以很好地与WordPress一起工作,即使服务器Cron更好。当有人访问你的WordPress网站时,WordPress cron会触发。

下面是一个新的时间表的例子(WordPress原生时间表只有每天,每天两次,每小时):

add_filter( 'cron_schedules', 'wc_dsr_add_custom_cron_schedule' );
function wc_dsr_add_custom_cron_schedule( $schedules ) {
    $schedules['fourdaily'] = array(
        'interval' => 21600, // 86400s/4
        'display'  => __( 'Four time daily' ),
    );
    return $schedules;
}
function wc_dsr_create_daily_backup_schedule(){
    //Use wp_next_scheduled to check if the event is already scheduled
    $timestamp = wp_next_scheduled( 'wc_dsr_cron_send_action' );
    //If $timestamp == false schedule daily backups since it hasn't been done previously
    if( $timestamp == false ){
        //Schedule the event for right now, then to repeat daily using the hook 'wc_create_daily_backup'         
        wp_schedule_event( time(), 'fourdaily', 'wc_dsr_cron_send_action' );
    }
}
//Hook our function , wc_dsr_cron_send_action(), into the action wc_dsr_cron_send_report
add_action( 'wc_dsr_cron_send_action', 'wc_dsr_cron_send_report' );
function wc_dsr_cron_send_report(){
    // do your job 
    wp_mail('test@test.com', 'Subject', 'Message');
}

在您的示例中,wc_dsr_cron_send_report()可能包含并使用portal_reminder.php。要很好地使用WordPress函数,您必须将此添加到portal_remind .php

define( 'WP_USE_THEMES', false );
require_once('pathto/wp-load.php); 

你可以在网上找到更多的例子