I customized a calendar plugin which shows today's birthdays and current month's list of wedding anniversaries in the home page of the site. I wrote a code in that plugin's displaying page using wp_mail
and mail will send. But this happens only when the site is visited. My code:
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 <[email protected]>' . "\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";
}
}
}
I heard about wp_cron
but when I searched in this forum about how to write cron
in WordPress I saw an answer like
Unfortunately the WordPress cron jobs are only triggered when your site is visited
If it is true then how can I send emails daily even without visiting the webpage? Is there any other way for this?