Mucus is produced by goblet cells - named for their resemblance to a goblet –- in the mouth and nose. The cells create mucus from water, proteins and polysaccharides so it can coat your sinus and mouth membranes, providing a yucky protective barrier.
Then, when we get sick, our body is trying to clear itself of bacteria and viruses. The goblet cells get revved up to flush away containments, which produces even more mucus. As Dr. Spiegel said, "A clever mnemonic is 'dilution is the solution to pollution.'" The more mucus we have running out of our sinuses, and through our mouths - in the form of phlegm - the more cleaning our bodies are trying to do.
Once your body begins to fight an infection, the mucus gears up and jumps in to get white blood cell waste out of the way. As our blood cell heroes fall, the mucus takes their waste with it as it leaks out of the body.
Normally, mucus is clear. But if the body is fighting a bacterial enemy, the mucus will become green or yellow as the white blood cells fight. When fighting the common cold (which is a virus, too small to fight), our white blood cells play less of a role so the mucus remains clear. So, if you're sick, look in your tissues and it might give you a clue of a bacterial versus viral infection.