在指定时间内自动发送来自wordpress的电子邮件

时间:2017-11-08 06:12:25

标签: php wordpress email cron

当我的ssl认证验证结束时,我想从我的wordpress网站发送一封自动发送的电子邮件。 (我的意思是在活动前3天)

我尝试使用wordpress cron,但电子邮件未在指定时间内发送。

有什么问题?

谢谢你的帮助!

我在functions.php中的代码:

// create a scheduled event (if it does not exist already)
function myprefix_custom_cron_schedule( $schedules ) {
    $schedules['every_six_hours'] = array(
        'interval' => 21600, // Every 6 hours
        'display'  => __( 'Every 6 hours' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );

//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) {
    wp_schedule_event( time(), 'every_six_hours', 'myprefix_cron_hook' );
}

///Hook into that action that'll fire every six hours
 add_action( 'myprefix_cron_hook', 'myprefix_cron_function' );

我在php中的代码:

function displayHostsSection(){
$opts = get_option('sslMail');
date_default_timezone_set('Europe/Budapest'); // CDT
$send_date = date('Y.m.d', strtotime("+3 days"));
if (isset($opts['hosts'])) {
foreach($opts['hosts'] as $host => $date) {
$d = ($date instanceof DateTime) ? $date->format('Y.m.d') : 'Unknown';



function myprefix_cron_function() {

if($send_date  == $d){

$to = get_option('admin_email');
$subject = "My Subject";
$txt = "My Text";
$headers = "From: $host " . "\r\n" .
"CC: ";

mail($to,$subject,$txt,$headers);

};
}

0 个答案:

没有答案