我正在尝试创建一个CRON以更新我的表USERS中的状态,我需要CRON分析每个用户,并且如果其中一个用户有30、15或0天的续约时间,请发送电子邮件通知我
现在,CRON会通过电子邮件通知我,但每个用户的信息都是错误的。
你能帮我做作品吗?
在这里,我向您展示CRON文件:
define('DB_HOST', 'localhost');
define('DB_TYPE', 'mysql');
define('DB_USER', 'database user');
define('DB_PASS', '123');
define('DB_NAME', 'database anme');
try {
$conn = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME."",DB_USER,DB_PASS);
$conn->exec("set names utf8");
$conn->exec('SET lc_time_names = "es_ES"');
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die('error!');
}
$status = '1';
$query = $conn->prepare('SELECT names, fPay FROM CLIENTS WHERE status = :status ORDER BY idClient DESC');
$query->execute(array(':status' => $status));
$result = $query->fetchAll();
foreach($result as $row){
$names = $row['names'];
$fPay = $row['fPay'];
$expiry = '0';
$now = time();
$payDay = strtotime($fPay);
$check = floor(30 - ($payDay / (60 * 60 * 24)));
if ($check <= "30") {
$sendto = "<mail@mail.com>";
$sendfrom = "<noreply@mail.com>";
$sendsubject = "subject";
$bodyofemail = "mail body";
include('Mail.php');
include('Mail/mime.php');
$message = new Mail_mime();
$text = "$bodyofemail";
$message->setTXTBody(utf8_decode($text));
$body = $message->get();
$extraheaders = array("From"=>"$sendfrom", "Subject"=> utf8_decode($sendsubject));
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send("$sendto", $headers, $body);
} else if ($check <= "15") {
//same email stuff...
} else if ($check <= $expiry) {
//same email stuff...
} else if ($check <= "-5") {
//same email stuff...
}
}
现在,仅显示最后一个用户名(并且该用户不在有效期内),并且我知道当前有效期为35个用户,如何解决此问题