Rotate Email Recipients

obriennolan 26 Jan, 2010
How can I get the results of a form to be sent to a single recipient based on group rotation? I have 3 users I want to share form results with, but I don't want any of them to get the same form result.

For example:
visitor #1 results are sent to user #1;
visitor #2 results go to user #2;
visitor #3 results go to user #3;
visitor #4 results go to user #1; and so on...

Any advice?
obriennolan 27 Jan, 2010
7 views and no replies in the last 24 hours. This must be something that Chrono can't do (even though my instinct and Joomla experience tells me there's always a solution).

Is anyone else facing this kind of issue?
GreyHead 27 Jan, 2010
Hi obriennolan,

Sorry, missed this the first time around.

You'll need to write some code to detect the user submitting the form and redirect the mail acccording. Thers is basic code for re-directng emails in one of hte FAQs (#36 I think) and there have been a few good threads about this recently (though none with this specific application).

obriennolan 27 Jan, 2010
Thanks for the reply. I checked out all the FAQ entries, and it seems #31 may be close to the solution I'm looking for. The major difference is that I don't want the visitor who fills out the form to select the email recipient, I would like recipient selection to be automatic.

What I'm trying to do is have the form results (leads) be distributed automatically among a handful of notification recipients in a round robin style, so no two recipients get the same lead and each new lead is sent to the next recipient on the list (or I guess the array??).

It seems the "On Submit Code - before email sent" is the place to put the solution. I just don't know what the should look like.
GreyHead 27 Jan, 2010
Hi obriennolan,

Ok so you need some extra code to do the distribution. As I see it you have two main choices:

1 The simpler route is to allocate randomly. Probably one line of code to pick an address out of the array. Over time this will work OK but on any given day one user might get a bunch of emails to respond to.

2 Rotate the emails. To do this you need some way of finding out who is next in the queue. You could do this with a text file saved somewhere, or by checking in the database to see who got the last one. Either way more compex code to write.

obriennolan 28 Jan, 2010
Thanks again GreyHead for the quick reply. (for the record, you look like a very hip, young blonde.)

It looks like option 2 is what I am looking for. Any ideas where I can look to find an example of the kind of code I will need, or tutorials of some sort? I've scoured the Internet universe to no avail so far. Perhaps I just don't know the right keywords to find the answer with Google. I don't mean to burden you, I just don't know where else to look.

Any advise you have is much appreciated.
GreyHead 28 Jan, 2010
Hi obriennolan,

That's why the random solution is easier.

I guess that you are saving the results to the database, then add an extra column to record the recipient.

Now, when you get a new form read the last result from the database and increment it (mod n) to get the next user number.
$rec_array = array('rec_1_email', 'rec_2_email', 'rec_3_email', ... );
$db =& JFactory::getDBO();
$query = "
  SELECT `rec_id``
    FROM `#__some_table`
    ORDER BY `cf_id` DESC 
    LIMIT 1;
$rec_id = $db->loadResult();
$rec_id = ($rec_id + 1) % count($rec_array);
JRequest::setVar('rec_id', $rec_id);
JRequest::setVar('rec_email', $rec_array[$rec_id]);
Not tested and will need de-bugging.

This topic is locked and no more replies can be posted.