如果今天在mysql中的日期如何发送电子邮件

时间:2017-07-13 06:45:55

标签: php mysql email cron jobs

我真正需要的是在今天field_number 7日期时在php中创建发送电子邮件的功能。 如果今天有lead_id 1 field_number 7数据,我只需要发送数据,例如lead_id 1。 当创建脚本时,我想将cron作业添加到此文件中,以便每天检查当天。 我的mysql数据如下所示:

Mysql data

我不是程序员,但据我所知,代码必须如下所示:

//authentication for database
$hostname = "localhost";
$username = "admin";
$password = "xxxxxx";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("notification",$dbhandle) 
or die("Could not select examples");

//execute the SQL query and return records
$result = mysql_query("SELECT * FROM tbl_lead WHERE pass_expiry >= DATE(NOW() + INTERVAL 1 DAY");

//variable for email message
$emailBody = "";
$headers = 'From: Pass Validity Reminder' . "\r\n" .
'Reply-To: myemail@email.com' . "\r\n" .
'Cc: ccemail@Wemail. com' . "\r\n".
'X-Mailer: PHP/' . phpversion();
$to = "myemail@email.com";

//fetch tha data from the database 
while ($row = mysql_fetch_array($result))
{

2 个答案:

答案 0 :(得分:0)

考虑图像中的表结构,使用下面的SQL语句来获取所有匹配的记录

$result = mysql_query("SELECT * FROM YOURTABLENAME WHERE lead_id='1' and field_number='7' and value=CURRENT_DATE();

<强>更新

$result = mysql_query("SELECT lead_id, form_id, field_number, value FROM YOURTABLENAME WHERE field_number='7' and value=CURRENT_DATE();

以上查询将提供field_number 7和value今天日期

的所有记录
while ($row = mysql_fetch_array($result)){
    if($row['lead_id']==1){
        //send email to all lead_id 1
    }

    if($row['lead_id']==2){
        //send email to all lead_id 1
    }

    .... Add leads to whom you have to send email
}

答案 1 :(得分:-1)

如果要根据当前日期检索数据,则可以使用此sql查询

titleView

此查询将选择所有今天的日期数据