【发布时间】:2014-05-22 09:10:15
【问题描述】:
我定制了一个日历插件,它在网站的主页上显示今天的生日和当前月份的结婚纪念日列表。我使用 wp_mail 在该插件的显示页面中编写了一个代码,邮件将发送。但这仅在访问该站点时才会发生。我的代码:
if($dat==date('Y-m-d'))/*$dat is the date of event from DB*/
{
if($eid!=''){ /*if recipient email id is not null*/
if($se!=1) /*if email is sending first time then($se=db column 'send'value) $se=0 otherwise it is 1*/
{
$to=$eid;
$sub="Birthday Wishes";
$msg='Happy Birthday '.$ev_title[$j];
$headers= 'From:Mysite <noreply@mysite.com>' . "\r\n".'Content-type: text/html';
$attachments=array(WP_CONTENT_DIR . '/plugins/spider-event-calendar/images/happybday.gif');
$rx=wp_mail($to,$sub,$msg,$headers,$attachments);
$wpdb->update($wpdb->prefix. "spidercalendar_event",array('send'=>1),array('id'=>$ev_id[$j]));/**/
//echo "email send";
}
else{
//echo "email already sent";
}
}
}
我听说过 wp_cron,但是当我在这个论坛上搜索如何在 wordpress 中编写 cron 时,我看到了类似的答案
Unfortunately the WordPress cron jobs are only triggered when your site is visited
如果是真的那么我怎么能每天发送电子邮件,即使不访问网页。还有其他方法吗?
【问题讨论】:
-
标准 cron 作业是最好的选择,您可以访问您的服务器命令行吗?还是有 cron 作业部分的 gui?
-
是的,我可以通过终端访问我的服务器..