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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵