What is happening is that your body's Cilia (which are tiny hair-like particles that line your lungs) are in a healing process.
They are first paralyzed and your body does not want to produce any mucus, therefore a dry cough sets in. As the cilia begin to heal themselves they start to clean all areas of your lungs. This is where you start to cough up all that awful mucus. The healing is a long process of change, even though some of the benefits come more quickly than others. Try drinking more water, herbal tea and even cough drops or candy. Sitting in the bathroom with the shower running or using a humidifier at night may also help to dislodge mucus.
It is also probably a good idea to talk to your doctor. Its possible that your smoking has been masking symptoms of some illness, and when you stop smoking the symptoms abruptly become noticeable.
Smoking does mask symptoms, so it is important to really know what your body is going through. Regular appointments with your doctor can be beneficial to rule out anything medical.