如何在PHP中向用户发送每日电子邮件通知? [英] How can I send a daily email notification to users in PHP?

查看:337
本文介绍了如何在PHP中向用户发送每日电子邮件通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的用户注册表单,复选框允许用户每天收到电子邮件通知,如果他们的任何项目的活动...很像Stack Overflow有通知任何新的xxx@example.com每日答案。

I have a simple user signup form with a checkbox that lets users get a daily email notification if there was activity on any of their projects...much like Stack Overflow has a "Notify xxx@example.com daily of any new answers".

我现在想在LAMP环境中实现这一点如下:

My current thinking to implement this in a LAMP environment is as follows:


  1. 如果用户希望接收每日电子邮件,请在用户数据库中设置一个布尔值。

  1. In the user database, set a boolean value if the user wishes to receive a daily email.

每天晚上(午夜),PHP文件被执行(可能通过cron作业),扫描项目数据库,以确定哪一个项目在那一天有活动。对于具有活动的项目,将选择项目所有者名称,并扫描用户表以检查用户是否希望接收每日电子邮件通知。如果是,添加到收件人列表;

Each night (midnight), a PHP file is executed (likely through a cron job) that scans through the project database to identify which projects had activity that day. For projects with activity, the project owner name is selected and the user table is scanned to check if the user wishes to receive a daily email notification. If yes, add to a recipient list; else, ignore.

问题/疑虑我希望在我开始实施之前,能得到一些指导: p>

Questions / concerns I have that would appreciate some guidance on before I start to implement:


  1. 我在共享托管环境中。

  1. I'm in a shared hosting environment. What precautions do I need to take from being misidentified as spam either by the hosting company or the receiving mail servers?

我需要chunk出来的东西,我需要采取什么预防措施,以免托管公司或接收邮件服务器被误认为垃圾邮件?收件人列表(每次50封电子邮件)和电子邮件每组?这是简单的睡觉(30);

Do I need to "chunk" out the recipient list (50 emails at a time) and email each group? Is this as simple as putting a sleep(30); between each call to mail()?

我正在使用CodeIgniter框架,并将使cron作业在控制器中调用相应的函数,午夜。如何限制来自仅cron作业的呼叫,以防止某些未经授权的用户从浏览器调用此功能?

I'm using the CodeIgniter framework and will have the cron job call the appropriate function in a controller to run this at midnight. How do I limit calls from only the cron job to prevent some unauthorized user from calling this function from the browser?

非常感谢。

推荐答案


  1. 如果你改变php中的From请确保将其更改为托管在该服务器上的域。

  1. If you do change the "From" header in php, make sure you change it to the domain that's hosted on that server. It looks suspicious when mail @a.com is being sent by b.com's servers.

我会个别发送电子邮件 foreach $ Users as $ User)... ,因为这允许您个性化电子邮件内容。

I would send the emails individually foreach ($Users as $User)..., since this allows you to personalize the email contents. Even if you don't need to personalize emails now, you might want to later, and the support for it will already be there when you need it.

即使您现在不需要个性化电子邮件,也可以稍后再提供支持。首先,我会将脚本存储在web根目录之外。我不知道CodeIgniter是否会让你这样做,但是没有必要的脚本永远由Apache服务。 Cron不在意脚本存储的位置。此外,我检查了脚本执行的时间。如果不是午夜,那么不要爆炸电子邮件。此外,您还可以保存日志,并检查以确保在发送前一天还没有发送电子邮件。

First, I would store the script outside of the web root. I'm not sure if CodeIgniter will let you do this, but there is no need for the script to ever be served by Apache. Cron doesn't care where the script is stored. Additionally, I've checked the time when the script is executed. If it's not midnight, then don't blast out the emails. Also, you could keep a log around and also check to make sure the emails haven't already been sent that day before sending.

这篇关于如何在PHP中向用户发送每日电子邮件通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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