据我了解,mailform.php 将每天 23 小时使用,对吗?
不,您需要0 23 * * * /path/to/script
让它在每天晚上 11 点运行。
这个 MySQL 只会为您提供两周前注册的用户(因此 regDate 恰好是两周前)
SELECT *
FROM `Your_Users_Table_Name`
WHERE `regDate` = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL -2 WEEK), '%Y-%m-%d')
然后在您的 cron 脚本中,您可以使用该查询来获取您的用户,然后遍历发送您的提醒或代码或其他任何内容的行。
粗略的例子
$sql = "
SELECT *
FROM `Your_Users_Table_Name`
WHERE `regDate` = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL -2 WEEK), '%Y-%m-%d')
";
if (false === ($result = mysqli_query($connection, $sql)) {
trigger_error('there was a query/sql problem', E_USER_ERROR);
}
if ($result->num_rows > 0) {
// ooo we found users from two weeks ago.
while ($row = mysqli_fetch_row($result)) {
// send email to user
mail($row['email'], 'The email Subject', 'The email message body');
// update the users table and set remind = 1
if (false === (mysqli_query($connection, "UPDATE `Your_Users_Table_Name` SET `remind` = 1 WHERE `email` = '".$row['email']."'"))) {
trigger_error('there was a query update problem!', E_USER_ERROR);
}
// sleep for 2 second so not to hammer mail systems and get flagged as abusive/spammer
sleep(2);
}
mysqli_free_result($result);
}
else {
// nothing to do today
}