php mail() 语句

发布于 2024-08-08 05:00:18 字数 440 浏览 6 评论 0原文

我正在尝试从数据库中获取所有用户信息并检查时间戳(十四天)并与时间进行检查,现在我的时间位可以工作,但当时间>时我无法将其发送给所有用户。十四天

 $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

林空鹿饮溪 2024-08-15 05:00:18

我建议在 SQL 中进行日期比较,而不是拉回查询中的所有数据:

SELECT * FROM accounts WHERE DateDiff(Now(), fourteendays) > 14

另外,数据库中的该列中有什么?如果它是时间戳,为什么不直接这样称呼它呢?我错过了什么吗?

I recommend doing the date comparison in SQL, instead of pulling back all of the data in your query:

SELECT * FROM accounts WHERE DateDiff(Now(), fourteendays) > 14

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?

一杯敬自由 2024-08-15 05:00:18

尝试。即大于或等于 14 天。

 if($timenow >= $days_time){
     mail( $users_email, $subject, $emailbody, $headers);
    echo "email sent!";
 }

另外 SELECT * 也是不好的做法。您应该只选择该查询中所需的字段。

Try. Thats greater than or equal to 14 days.

 if($timenow >= $days_time){
     mail( $users_email, $subject, $emailbody, $headers);
    echo "email sent!";
 }

Also SELECT * is bad practice. You should only select the fields you need in that query.

好听的两个字的网名 2024-08-15 05:00:18

我假设您已经在脚本中之前的某个位置设置了“$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

偏爱你一生 2024-08-15 05:00:18

或者甚至

SELECT * FROM accounts WHERE fourneendays < (NOW() - INTERVAL 14 DAYS);

我假设 NOW() 给出了您想要的时间戳 - 它不会是 UTC (但您知道这一点,对吧)?

Or even

SELECT * FROM accounts WHERE fourneendays < (NOW() - INTERVAL 14 DAYS);

I am assuming that NOW() gives the timestamp you want - it won't be in UTC (But you knew that, right)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文