发送提醒电子邮件与php和mysql,而无需cron-job? [英] send reminder emails with php and mysql WITHOUT cron-job?

查看:85
本文介绍了发送提醒电子邮件与php和mysql,而无需cron-job?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚制作了一个php脚本,该脚本将在约会开始前2天向网站的管理员发送电子邮件提醒.我本来要自动化脚本来执行cron作业,只是意识到我托管的人(疯狂的域)似乎没有Cron作业

I just made a php script that will send email reminders to admins of a website 2 days before an appointment begins. I was going to automate the script to run through a cron job, only to realise who I am hosting with (crazy domains) does NOT appear to have Cron Jobs

没有cron-jobs,有没有办法做到这一点?如果是这种情况,我不介意去其他服务提供商.我已经进行了很多搜索,到目前为止,我的理解是我需要Cron Jobs来处理这些类型的事情吗?

Is there ANY way of doing this without cron-jobs? I do not mind going to a different service provider if that is the case; I have done quite a bit of searching around, and my understanding so far is that I need Cron Jobs for these types of things?

这是我到目前为止所做的脚本:

Here is the script I did so far:

<?php include "../connect-to-database.php";  ?>

<?php   
    $date = date("Y-m-d");
    $mod_date = strtotime($date."+ 2days");
    $newDate = date("m/d/Y",$mod_date);

    $sqlCommand = "SELECT * FROM eventcalender WHERE eventDate='$newDate'" ;
    $query = mysql_query($sqlCommand) or die(mysql_error());
    $count = mysql_num_rows($query);

if ($count >= 1){
        while($row = mysql_fetch_array($query)){
            $ID = $row["ID"];
    $schedule_title = $row["Title"];
    $schedule_description = $row["Detail"];
    $importance_level = $row["importance_level"];
    $meeting_datetime = $row["eventDate"];
    $contacts_involved = $row["contacts_involved"];
    $meeting_occurred = $row["meeting_occurred"];

    $mid = mysql_insert_id();
    $search_output .= "<ul>
                <li>
                    <h4>".$schedule_title."</h4>
                    <p><b>Time: ".$meeting_datetime."</b></p>
                    <p>People/Persons involved: ".$contacts_involved."</p>
                    <p>Meeting Occurred?: ".$meeting_occurred."</p>
                    <a href='uniqueMeeting.php?ID=".$ID."'>View more details of this meeting</a>
                    <p><a href='editschedulePage.php?mid=$ID'>Edit This Meeting</a></p>
                    <p><a href='scheduleList.php?deleteid=$ID'>Delete this meeting</a></p>
                </li><br/>                  
            </ul>";

            $sendMail = true;
        }

}

if($sendMail){  
    $admin = "SELECT * FROM admin" ;
    $queryAdmin = mysql_query($admin) or die(mysql_error());
    $adminCount = mysql_num_rows($queryAdmin);
    $recipients = array();
        if ($count >= 1){
            while($row = mysql_fetch_array($queryAdmin)){

            $subject ='A-CRM; UpComing Activities';
            $msg = $search_output; 
            $to = $row['email_address'];
            mail($to, $subject, $msg);
            }   
        }
}

?>

是的,我确实意识到我是绝对不使用mysqli的人,我将在完成本网站后立即开始

Yes I do realise I am an absolute horrible person for NOT using mysqli, and I will start to as soon as I finish this website

推荐答案

如果经常访问您正在构建的站点,则可以在数据库中保留时间戳(或日期时间或其他内容),以备下次脚本执行时使用.跑.然后将该脚本包含在您的网站中(每个页面或仅对其进行选择).

If the site you're building is visited frequently, you can keep a timestamp (or datetime or whatever) in your database holding the next time the script has to run. Then include the script in your website (every page or just a selection them).

如果当前时间等于或大于数据库中的时间,请运行脚本并将数据库中的时间设置为脚本下一步必须运行的值.这样,脚本将由站点的访问者之一执行,而他们却不知道.

If the current time is equal or greater than the time in the database, run the script and set the time in the database to the value the script has to run next. In this way, the script will be executed by one of the visitors of the site, without them knowing.

这篇关于发送提醒电子邮件与php和mysql,而无需cron-job?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆