我编写了一段代码,允许向所有在一定时间内未登录的用户发送电子邮件。
HTML 是:
<select name="criteria">
<option value="14"<?php if("14" == $form->value("criteria")){ echo 'selected="selected"'; }?>>14 days</option>
<option value="28"<?php if("28" == $form->value("criteria")){ echo 'selected="selected"'; }?>>28 days</option>
<option value="90"<?php if("90" == $form->value("criteria")){ echo 'selected="selected"'; }?>>3 months</option>
<option value="180"<?php if("180" == $form->value("criteria")){ echo 'selected="selected"'; }?>>6 months</option>
<option value="365"<?php if("365" == $form->value("criteria")){ echo 'selected="selected"'; }?>>1 year</option>
</select>
然后在另一个文件中接收,下面的代码接管
$time = time() - ($criteria * 0 * 0 * 0);
$q = $admindb->getReminderCustomerEmail($time);
数据库查询如下:
function getReminderCustomerEmail($time){
global $database;
$q = "SELECT email, title, forename, surname FROM ".TBL_USERS." WHERE last_logged <= '$time'";
return mysql_query($q, $database->myConnection());
}
想法是,如果您选择 14 天,将向所有在过去 14 天内未登录的用户发送邮件。
目前,这还没有发生,它似乎只是向所有用户发送消息。
我认为错误一定在行中
$time = time() - ($criteria * 0 * 0 * 0);
有什么想法吗?谢谢
最佳答案
任何数乘以零总是为零。
您是否正在寻找 ($criteria * 86400)
或许(以获得天数)然后从 time()
中减去 that 值?
您还可以使用 strtotime
:
strtotime('-' + $criteria + ' day',time());
关于php - 操纵 time() 函数以允许发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6470432/