为基于Web的应用程序实施自动提醒电子邮件功能 [英] Implement an automatic reminder email feature for web based application

查看:321
本文介绍了为基于Web的应用程序实施自动提醒电子邮件功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的网络应用程序创建一个功能,一旦用户在我的数据库中输入,每4周向他们发送一封电子邮件,提醒他们,例如给出一些反馈。我听说cron工作是什么Im寻找,但Im好奇还有什么是在那里,有可能是一个php脚本存在或一个简单的方法来做吗?



我想要一个倒计时,一旦他们进入数据库开始倒计时直到4周已经过去,然后调用一个php文件或发送一个我选择的电子邮件给他们。如果这是可能让我知道!谢谢

解决方案

我会说使用cron作业(它可以在某个时间运行,一个电子邮件),cron作业可以调用一个php脚本,它将查看所​​有的用户和检查他们注册,并查看是否有人注册了4周前(或其中的一些倍数)。



Cron作业 p>

登录服务器上的shell,输入sudo crontab -e,输入如下:

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

在此示例中,phpscript.php将在每天14:30(下午2:30)运行。但这并不意味着它会每天给所有的用户发电子邮件!请参阅下面的脚本。



PHP脚本

 <?php 
#获取所有用户(或者您的查询只能选择注册(4周)* n以前的用户)
$ result = mysql_query('SELECT * FROM user') ;
$ users = array();
while($ row = mysql_fetch_assoc($ result))$ users [] = $ row;

#循环通过用户和(如果你还没有检查)查看哪些已注册(4周)* n ago
foreach($ users为$ user){
#获取秒数并将其转换为天数
$ today =(int)(strtotime(date('c'))/ 60/60/24);
$ signup_day =(int)(strtotime($ user ['signup_date'])/ 60/60/24);
#检查注册后的天数是否为28的倍数(4 * 7)
if(($ today - $ signup_day)&& amp;($ today - $ signup_day)%28 = = 0){
send_mail_to($ user);
}
}
?>


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

解决方案

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);
    }
}
?>

这篇关于为基于Web的应用程序实施自动提醒电子邮件功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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