php mail() 语句
我正在尝试从数据库中获取所有用户信息并检查时间戳(十四天)并与时间进行检查,现在我的时间位可以工作,但当时间>时我无法将其发送给所有用户。十四天
$result1 = mysql_query("SELECT * FROM accounts") or die (mysql_error());
while ($row1 = mysql_fetch_array($result1)) {
$users_email = $row1['email'];
$user_name = $row1['user'];
$days_time = $row1['fourteendays'];
if($timenow > $days_time){
mail( $users_email, $subject, $emailbody, $headers);
echo "email sent!";
}
}
I am trying to get all the users information from the database and check the timestamp (fourteendays) and check it with the time now I got the time bit working but I can't get it to send to all the when the time is > fourteendays
$result1 = mysql_query("SELECT * FROM accounts") or die (mysql_error());
while ($row1 = mysql_fetch_array($result1)) {
$users_email = $row1['email'];
$user_name = $row1['user'];
$days_time = $row1['fourteendays'];
if($timenow > $days_time){
mail( $users_email, $subject, $emailbody, $headers);
echo "email sent!";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议在 SQL 中进行日期比较,而不是拉回查询中的所有数据:
另外,数据库中的该列中有什么?如果它是时间戳,为什么不直接这样称呼它呢?我错过了什么吗?
I recommend doing the date comparison in SQL, instead of pulling back all of the data in your query:
Also, what is in that column in the database? If it is a timestamp, why don't you just call it as such? Am I missing something?
尝试。即大于或等于 14 天。
另外 SELECT * 也是不好的做法。您应该只选择该查询中所需的字段。
Try. Thats greater than or equal to 14 days.
Also SELECT * is bad practice. You should only select the fields you need in that query.
我假设您已经在脚本中之前的某个位置设置了“$timenow”变量,并且在比较时我会确保检查两种时间格式是否相同。这是我过去的问题。
有关日期相关的 php 信息,请访问以下链接
http://ca.php .net/manual/en/function.date.php
I assume you have already set the '$timenow' variable somewhere previous in the script and I would make sure to check that both time formats are the same when comparing. That was my problem in the past.
For date-related php information, visit the following link
http://ca.php.net/manual/en/function.date.php
或者甚至
我假设 NOW() 给出了您想要的时间戳 - 它不会是 UTC (但您知道这一点,对吧)?
Or even
I am assuming that NOW() gives the timestamp you want - it won't be in UTC (But you knew that, right)?