Now re-reading my post I see the misunderstanding.
What I meant is that my client does it by hand (check the users , choose the event , and pressing send) because he chooses different users for different event types.
Yes, but sending messages right from the controller is totally unreliable (what if the connection is suddenly lost, or some other error happens, and you have no idea how many messages has already been sent). Nobody wants email duplicates, you know.
If you still don’t want to use message queue, consider ajax request. So you check some users, select an event and submit this data via ajax to some action, that processes it and returns the result (was it successful, how many messages has been sent and so on).
The messaging code is pretty simple, basically it’s just
That was my plan: send ajax through clientscript from the view to a controller function that sends the mail.
The easiest solution is the best for me (under client I mean the person for whom I write the app as part of my degree final project - I’m a student and quite new to yii)
Thats all ? If I send ajax to user, subject, name and var’s it’ll work?
I had no idea cron can be used for such thing , I’ll try to find some reading on the subject. (though if anyone have any info about cron mailing I’ll be happy to get some tips)
Well, cron itself can do only one thing: run some job periodically.
So you can create console application that checks some queue (db table, for example) for tasks, and, if any, process these tasks.
Let’s consider a simple table tbl_mailing that has these fields:
id (unique identifier for job)
name (internal name for job)
message (text field containing mail body)
user_ids (comma-separated list of user ids that should get this mail).
So you check some checkboxes in clients list, fill the message text (probably some placeholders should be used also, like "Hello, %username%!") and submit the form. This form is processed by action and new Mailing record is created. Ok, the job is in queue.
Let’s suppose that the cron runs every N minutes. So every N minutes your console app is started. It checks for new unfinished jobs (for example, $job = Mailing::model()->find(‘user_ids IS NOT NULL’));
If there’s an active job, console app explodes user_ids, finds the users from this list and starts mailing.
Every time email is successfully sent, corresponding item is removed from the array.
When the mailing is done (for example, you want to send only three emails in a row), the rest of the array is imploded and stored back to tbl_message. When the list is empty, NULL is stored instead.
This is the very basic example, so it can’t be taken as a working code. But I think you got the idea.
I’m guessing that user_ids should be int? and since checkbox is creating an array I guess that under “explode” you mean a counter that reads the id’s separately ?