douba9654 2014-05-14 13:32
浏览 48
已采纳

Cron Job使用php脚本发送电子邮件时出错

I have database with last_logoff_date. I recently added new column last_login_date. I am trying to send email to members whose last_login_date is greater than 10 days and less than 120 days. As I have created last_login_date column recently with timestamp atrribute, every row is set as 0000-00-00 00:00:00 by default, and now onwards when member get login to site, current timestamp is added to this field. Now with below code, email is getting send to members with last_login_date 0000-00-00 also and even to members logged in before 1 day too.

In short, email gets delivered to all memebrs with member_status=1 irrespective of last_login_date...

I could not find out the error. This php is script is used for cronjob.

My Code is as follows..

 <?php
 include("db1.php");
 require("class.phpmailer.php");
 $mail = new PHPMailer();
 $login_check=mysql_query("select * from table name where member_status= '1' AND last_login_date != '0000-00-00' ");
 while($datelogin=mysql_fetch_array($login_check)){ 
     mysql_query("select * from table name WHERE reg_id =".$datelogin['reg_id']);   

 $date1= date("Y-m-d");
 $date2=date("Y-m-d",strtotime($datelogin['last_login_date'])); 
 $dateDiff = strtotime($date1) - strtotime($date2);
 $fullDays = floor($dateDiff/(60*60*24));

     if($fullDays >= 10 && $fullDays <= 121){   

 ob_start();
 ?>

 email  data.....

 <?
 $body=ob_get_contents();
 ob_end_clean ();    
 ........
 }
 }
 ?>
  • 写回答

1条回答 默认 最新

  • doupeizheng3918 2014-05-14 13:41
    关注

    use the following query:

    SELECT *
    FROM table
    WHERE member_status = '1'
    AND last_login_date BETWEEN DATE_SUB(NOW(), INTERVAL 120 DAY) AND DATE_SUB(NOW(), INTERVAL 10 DAY)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle