首页 > 解决方案 > 在特定日期发送电子邮件提醒并且不知道 cron 工作

问题描述

遇到与在某个特定日期发送电子邮件提醒相关的问题。我搜索了一些有用的代码,并且有几个网站提到了 cron 工作。但我对此一无所知。所以任何人都让电话告诉我实际的答案。这里我附上代码。

include('connection.php');
if (isset($_POST['submit'])) {
$name       = $_POST['name'];
$mobile     = $_POST['mobile'];
$email      = $_POST['email'];
$datenoted  = $_POST['datenoted'];
$subject    = $_POST['subject'];
$sel = "insert into reminders(remindr_name,remindr_mobile,reminder_email,remindr_subject,remindr_date,curdate,curtime) values('$name','$mobile','$email','$subject','$datenoted',CURDATE(),CURTIME())";
if(!mysqli_query($link ,$sel ))
{
echo "Error " .mysqli_error($link);
}
else
 {

$sqlCommand = "SELECT 
        u.remindr_id
        , remindr_name
        , remindr_subject
        , remindr_date
        , reminder_email
        FROM reminders u
        WHERE remindr_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
        ";

        $query = mysqli_query($link, $sqlCommand) or die (mysqli_error($link));

        //fetch the data from the database 
$message = '';
$email = '';
        while ($row = mysqli_fetch_array($query)) {
    $arr_ids[] = $row['remindr_id'];

       $prev_Email = $email;
        $headers = "From: mail@georgeprojects.com\r\n";    
        $subject = "GeorgeProject Reminder";
        $id = $row['id'];
        $owner = $row['remindr_name'];
        $email = $row['reminder_email'];

if(date("Y-m-d") == $row['remindr_date']) {

if(!empty($email) && $email != ""){
$message = "Hi: {$row['remindr_name']} , \n\n There is a reminder for you on the date : {$row['remindr_date']} regarding the subject {$row['remindr_subject']}\n";

    $to = $email;
    $sendmail = mail($to, $subject, $message, $headers);

 }
 }

 }

header('Location: reminderInsert.php');
} 
}

标签: phpzend-framework

解决方案


推荐阅读