Implement an automatic reminder email feature for web based application

老子叫甜甜 提交于 2019-12-07 18:19:40

问题


I would like to create a feature for my web application that once a user is entered in my database, every 4 weeks an email is sent to them reminding them to, for example, give some feedback. I've heard cron job is what Im looking for but Im curious what else is out there, is there maybe a php script that exists or an easy way to do it?

I want something like a countdown from once they enter the database to start counting down till 4 weeks has passed then call a php file or something that sends an email of my choosing to them. if this is possible let me know! thank you


回答1:


I would say to use a cron job (it could run everyday at a certain time that would be good to send an email), and the cron job could call a php script that would look through all your users and check when they signed up, and see if anyone signed up 4 weeks ago (or some multiple of that). For anyone who meets this condition, you could go through a loop and send them emails with the mail() function.

Cron Job

Log into a shell on your server and type "sudo crontab -e" and type in something like this:

30 14 * * * php path/to/some/phpscript.php

In this example, phpscript.php is going to be run at 14:30 every day (2:30 pm). But that doesn't mean it's going to email all the users every day! See the script below.

PHP Script

<?php
# get all users (or your query could choose only users who signed up (4 weeks)*n ago)
$result = mysql_query('SELECT * FROM user');
$users = array();
while($row = mysql_fetch_assoc($result)) $users[] = $row;

# loop through users and (if you didn't already check) see which ones have signed up (4 weeks)*n ago
foreach ($users as $user) {
    # take the number of seconds and convert it to number of days
    $today = (int)(strtotime(date('c')) / 60 / 60 / 24);
    $signup_day = (int)(strtotime($user['signup_date']) / 60 / 60 / 24);
    # check if the amount of days since signup is a multiple of 28 (4*7)
    if (($today - $signup_day) && ($today - $signup_day) % 28 == 0) {
        send_mail_to($user);
    }
}
?>


来源:https://stackoverflow.com/questions/17634089/implement-an-automatic-reminder-email-feature-for-web-based-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!