Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress Cron没有';t激发wp_mail()而不是php mail()函数_Php_Wordpress_Cron - Fatal编程技术网

Wordpress Cron没有';t激发wp_mail()而不是php mail()函数

Wordpress Cron没有';t激发wp_mail()而不是php mail()函数,php,wordpress,cron,Php,Wordpress,Cron,我试图在cronjob任务中使用wp_邮件,但没有发送电子邮件。相反,纯php函数mail()可以工作 问题1):为什么mail()可以工作,而wp_mail不能 问题2):手动调用www.domain.de/wp-cron.php会触发电子邮件。但是收到的电子邮件的html电子邮件正文仍然是一个字符串,并且没有翻译成html。你知道为什么吗 寻找解决方案,找到了一些。根据本文(),我将cronjob设置为: 设置自定义间隔: function example_add_cron_interval

我试图在cronjob任务中使用wp_邮件,但没有发送电子邮件。相反,纯php函数mail()可以工作

问题1):为什么mail()可以工作,而wp_mail不能

问题2):手动调用www.domain.de/wp-cron.php会触发电子邮件。但是收到的电子邮件的html电子邮件正文仍然是一个字符串,并且没有翻译成html。你知道为什么吗

寻找解决方案,找到了一些。根据本文(),我将cronjob设置为:

设置自定义间隔:

function example_add_cron_interval( $schedules ) {
$schedules['five_seconds'] = array(
    'interval' => 5,
    'display'  => esc_html__( 'Every Five Seconds' ),
);
$schedules['daily'] = array(
    'display' => esc_html__( 'Once Daily' ) 
);
return $schedules;
}
add_filter( 'cron_schedules', 'example_add_cron_interval', 999 );
激活cronjob:

function cron_activation() {
    if( !wp_next_scheduled( 'dbs_cron_hook' ) ) {  
        wp_schedule_event(time(), 'daily', 'dbs_cron_hook' );  
    }
}
add_action('init', 'cron_activation');
执行逻辑: 函数我的任务函数(){

问题1仍然想知道

$max_hours = 336; // entspricht 2 Wochen
global $post;
$args = array( 'post_type' => 'bookings', );
$booking_listing = new WP_Query( $args );
$mail_body = '<table>';

if( $booking_listing->have_posts() ) :
    while( $booking_listing->have_posts() ) : $booking_listing->the_post();

        $post_id = get_the_ID();
        $email_sent_timestamp = intval( get_post_meta( $post_id, 'approvement_email_sent', true ) );
        $event_id = intval( get_post_meta( $post_id, 'event_id', true ) );

        if( $email_sent_timestamp != 0 ){

            $date = date_create();
            $now_timestamp = date_timestamp_get($date);
            $hoursPassed = diff_timestamp( $now_timestamp, $email_sent_timestamp );

            var_dump($hoursPassed["full_hours"] >= $max_hours);

            if( $hoursPassed >=  $max_hours ){

                update_post_meta( $event_id, 'event_reserved', intval(0) );
                $mail_body .= '<tr><td>BuchungsNr ' . $post_id . ': 2 Wochen sind abgelaufen.</td></tr><tr><td>Der Termin ' . $event_id . ' wurde wieder aktiviert.</td></tr>';

            }
        }

    endwhile;
else:
    wp_send_json_error( "No events found" );
endif;

$mail_body .= '</table>';

var_dump($max_hours);

// wp_mail( 'xxxxx@xxxxxxx.xxx', 'Rervierung ' . $post_id . ' abgelaufen', $mail_body );

mail( 'xxxxx@xxxxxxx.xxx', 'Rervierung ' . $post_id . ' abgelaufen', $mail_body );

}
add_action( 'dbs_cron_hook', 'my_task_function' );
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail( $to, $subject, $mail_body, $headers );