开发者

Sending emails in bulk through php and codeigniter

开发者 https://www.devze.com 2023-03-18 23:57 出处:网络
I am building up a script which takes user registration and upon registration it sends an email to the user for email validation. Now upon validating the email when user logs in there are various acti

I am building up a script which takes user registration and upon registration it sends an email to the user for email validation. Now upon validating the email when user logs in there are various activities the user performs when an automatic email is sent to the other user with whom the user interacts on the site.

For example the when a user sends a private message to his follower on the site an automated email is also sent to the followers email address which informs him of the user activity performed.

Now consider there around thousand users on the site which perform around 2000 to 5000 activities of sending auto emails daily.

I am using codeigniter to build up my website and I would like to know the best approach through which I can design the system so that the email is properly deli开发者_如何转开发vered without fail.


Seems like a case for an event/message queue.

Web generated events - registration, direct messages to followers, etc - add a message/task/item into the work/message queue. A cron process consumes the queue, actually performing the send. Note that "message" here is just an object or a db record containing information sufficient to perform the assigned task: send message of type X from sender/user Y to recipient/user Z, etc. It could even have audit fields for current status, when the item was added to the queue, when it was completed, etc. Maybe the queue is purged of completed tasks after some period of time.

On the upside, your web processes - registration, etc - aren't waiting for these messages to go out, so the client waiting at the browser end gets snappier web response.

On the downside, the web process really can't know for sure if the task was performed; all it can know is that the request has been passed along to the queue for eventual processing.

Still, you could offer web interfaces to the user that report the status of pending/completing requests and that might be sufficient.

Just thinking out loud... ;-)


I suggest you use third-party services like postageapp, and others.

Sending emails is pain and hard to do right, specially when trying to send lots of them.

I suggest postageapp because I've used their service which is good and they have a CodeIgniter library!


I would add all messages to a database and let a cronjob sent these e-mails every X minutes. You could sent all e-mails at once or you sent like X messages every X minutes. To make sure that registration e-mails get sent first, you could set up some sort of priority. They get a higher priority and will be sent first.

If you want to make some kind of forum, I suggest you sent one mail only when a topic gets a new reply till the user has viewed the topic. This makes sure that you have less traffic and the user gets less spammed. Not sure if you have some sort of functionality like this in your website, but it's just a hint if you have something like this.


You should take 2 steps:

a) Save user activity log in the database and then use cron to send email to users, if you will not use cron then it will affect your system considerably.

b) While sending emails using cron you should use third party email solutions like Mandrill or Sendgrid otherwise if you send too much email then your emails can be marked as spam (remember these both services are not free but you can create developers version to test the functionality)

0

精彩评论

暂无评论...
验证码 换一张
取 消