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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作