Send emails to users in Yii (about multiple threads and etc.)

Dear all,

I am doing email-subscriptions in my application and I need to send emails to the users who have subscribed some specific topics when there are new replies.

I meet a problem now. If I send the email to all users at once, each user will see each other’s email in the field “To” because the email have multiple recipients. If I Bcc the email to them, users will not see their own email address in the “To” field…

So do I have to use “for …each” to send a single email a thousand times to each user? I can’t send it to all of them at once?(To make sure the “To” field only contain a specific user’s email but not all users’ email addresses?)

Also, I’ve heard there is a way to make a queue in Yii and let the Yii’s command line tool do all the stuff…(push all the email tasks in a queue…)

Any ideas?


I don’t really know what’s so bad about the BCC-solution, but: You could let a cronjob run every five minutes and let that send all those emails.

I personally think the Bcc solution is fine. However, I never find a website’s email subscription is sending to someone else and Bcc to me…

So… :D

True enough.

But there are really two usage scenarios.

You either need to send a personalized message, or not. If it is a generic notification the BCC solution would be the fastest and most efficient.

If you need to send personalized messages and have more than a small number of them you will probably want to setup a mail queue. Otherwise your script will wait (blocking) on all the messages to be sent. Roll your own or use Pear Mail_Queue. There are a few threads here describing how to do so.

In general… you create a database table that holds the queued messages and then run the mail_queue script via cron at whatever interval you want. You configure it to send N emails at a time until the queue is exhausted.

Another idea besides Pear Mail_Queue is to look at some popular open source forum software and see how they are handling this situation. Imagine a forum with 1000 people watching a topic and having to send out update notifications.

Thanks for your help! That is very helpful. I will keep using Bcc these days and will find some open sources softwares to handle the email.

Or I will use Pear.