Email Rotation System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daneditty
Forum Newbie
Posts: 6
Joined: Fri Nov 06, 2009 10:27 am

Email Rotation System

Post by daneditty »

I am trying to create a system where 1 person on my team is emailed a lead that is posted to my db and then the next lead that is posted is then emailed to another person on my team and so on. Thus, 1 lead/email per person and it needs to rotate through all my team members as leads continue to be posted.

On top of that I would like to be able to say this person gets 2 leads/emails for everyone else's 1 lead/email, so that my most efficient sales people are kept busy.

Any thoughts to help me get started would be much appreciated!

Dane
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Email Rotation System

Post by SimpleManWeb »

Well, I have a pretty good idea that could handle the first half of your request. This part:
I am trying to create a system where 1 person on my team is emailed a lead that is posted to my db and then the next lead that is posted is then emailed to another person on my team and so on. Thus, 1 lead/email per person and it needs to rotate through all my team members as leads continue to be posted.
This part is going to require some extra thought:
On top of that I would like to be able to say this person gets 2 leads/emails for everyone else's 1 lead/email, so that my most efficient sales people are kept busy.
Here's a quick run down of how I would do it. Create a table in a MySQL database that contained all of your sales people in it. Put in their name, email address, any other important info and then also create a column called something like "LeadCount". Then, whenever a lead is submitted to the site, you can simply select the person from the database with the fewest number of leads, email him the info, increase his lead count by 1 and you're good to go.

Let me know if you need any code examples.
daneditty
Forum Newbie
Posts: 6
Joined: Fri Nov 06, 2009 10:27 am

Re: Email Rotation System

Post by daneditty »

Hey thanks SimpleMan - One situation I forsee with:
Here's a quick run down of how I would do it. Create a table in a MySQL database that contained all of your sales people in it. Put in their name, email address, any other important info and then also create a column called something like "LeadCount". Then, whenever a lead is submitted to the site, you can simply select the person from the database with the fewest number of leads, email him the info, increase his lead count by 1 and you're good to go.
is what happens when I add a new sales person? Their numbers would be way less so I would have to some how restart the count otherwise they would get all the leads until their count caught up and I can not count on a certain number of leads per day or month etc.

I was thinking of doing something such as taking the number of sales people and inserting that # into another table and having it count up to that number and then start over again but I still have the issue of getting someone leads/emails twice to an others 1?

Thanks for your feedback SimpleMan!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Email Rotation System

Post by McInfo »

This isn't a complete thought, but I'll throw it out there anyway. For each person, keep a timestamp of when the last lead was awarded and a minimum wait duration. The wait duration is subtracted from the actual difference between the timestamp and the current time. This affects the frequency with which leads are awarded to an individual (or the chance of getting a lead). Award leads to the person who has waited longest, taking into account the wait duration so that the distribution is unbalanced in favor of individuals with shorter wait durations.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 4:29 pm, edited 1 time in total.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Email Rotation System

Post by SimpleManWeb »

is what happens when I add a new sales person? Their numbers would be way less so I would have to some how restart the count otherwise they would get all the leads until their count caught up and I can not count on a certain number of leads per day or month etc.
Well, this would really all depend on how exactly you will be adding them to the database. If you were adding them by hand, you would need to go into your current table and look at your lowest Lead Count and then just match that when you enter your new person. If you created code to add the person for you, you could easily get that number first and then use it in your insert statement.

Although your idea of have two tables would work, you would need to update both tables whenever a sales person is added, so keep that in mind. That might get kind of burdensome if you make changes often.

Here's a potential solution for your 2 to 1 idea, if you use my original idea. In addition to your "LeadCount" column, create another column "Priority" or something like that. For most of your sales people, simply give them a priority of 1, for some of them it would be 2. Then, when you are doing the select statement, you could simply divide "LeadCount" by "Priority" and sort it ASC. Then just take the top person. I believe that should give you what you need.
daneditty
Forum Newbie
Posts: 6
Joined: Fri Nov 06, 2009 10:27 am

Re: Email Rotation System

Post by daneditty »

i got it! - I created 3 tables - user's table with their info, ie email address, and a priority column. An email_group table with userid's, groupid, leadid, timestamp, and pk. Thirdly a groupid table with the number of leads sent along with the total of number to be sent with this group which is based on summing the priorities.

If I want someone to receive 2 leads to everyone else's 1, I give them a priority of 2 and when the email_group is created their userid gets dumped into the table twice which correlates to the total number to be sent in the groupid table. It sends them based on the userid's that have not received leads from the email_group table. When the number of leads sent = the total number of leads to be sent. It creates a new groupid, querying the priorities and who has them.

It isn't pretty but it works!

Now I have to figure something else out - how to put a cap on the number of leads per day they receive? It never ends ;-)

Thanks for your inputs.

Dane
Post Reply