• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Managing contact info

Hi...We have a contact form on our website that users fill out and submit to us.  Right now all that info is sent to one e-mail address.  We like to forward it to our closest retail location based on the users zip code.  Any ideas?  Thanks
1 Solution

I dont know if you are using a backend database, such as MySQL or MSSqlServer, but this is one example using databases:

Create an email address for each of your retail locations - you probably already have these.  Store these in a table such as:

   id   | distributor          |   email  
    1   | Palo Alto            |  sfbob@mydomain.com
    2   | Gump Valley       |  gvalley@mydomain.com

Create a table with ranges of zip codes as follows:

  start    | end      | distributor
  94040  | 96049  | 1
  94030  | 96039  | 1
  10000  | 10100  | 2

Note that two rows zipcode ranges are given to one distributor here, that's so that areas can overlap.

Then, if a customer gives you a zipcode, you can find the distributor email with:

   SELECT email FROM distributors WHERE id = (SELECT distributor FROM zipcodes WHERE start <= 94041 AND end >= 94041)

There is lots of different ways to achieve the same thing.  There are more efficient ways to implement the database tables and the SQL queries - it all depends on what you want to do, what you have available and how confident you are with the techniques.  You don't even need a database as long as you are willing to maintain a file in a format similar to:

  94030 96039 sfbob@mydomain.dom
  94040 96049 sfbob@mydomain.dom

...but the principle is basically the same - record the zipcode ranges that are assigned to each distributor, and then use some lookup mechanism to find the correct distributor

what language are you writing it in?
The code above is SQL and you can use it from within every programming languages.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now