Implement an automatic reminder email feature for web based application

随声附和 提交于 2019-12-06 01:15:48

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