Phlegm is the mucous secretion of the respiratory passages. The cilia cells that line these passages are continually driving the phlegm upward to the throat, where it triggers the swallow reflex so that dust and other foreign bodies can be removed from the lungs.
When you are healthy, your phlegm is thin and clear and despite swallowing about 1.5 litres every day, you hardly notice. If you have a cold or other respiratory infection, or you are a heavy smoker, your phlegm may be thicker and darker coloured. This is caused by trapped particles, bacteria, viruses, white blood cells and antibodies.
As unappetising as this cocktail may sound, there isn’t really very much more harm that can come to you from swallowing it. Any pathogens have just come from your lungs where they already had almost direct access to your bloodstream. In your stomach they will be destroyed by powerful acids and enzymes and isolated from your body by the thick mucus layer on the stomach wall.