【发布时间】:2015-11-14 22:57:46
【问题描述】:
我正在制作一个程序,使用wp_schedule_event 在一个小时内检查和发送电子邮件,但它对我不起作用.. 有人知道我的情况吗?这是我的代码,我把它放在我的自定义插件myplugin-function.php
register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
wp_schedule_event(time(), 'hourly', 'my_hourly_event');
}
function do_this_hourly() {
$headers = "From: webmaster <webmaster@test.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail('mymail@test.com','Test','Hello',$headers);
}
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
wp_clear_scheduled_hook('my_hourly_event');
}
【问题讨论】:
标签: php wordpress scheduled-tasks