The valve that fails
Stomach is separated from the gullet by a sphincter muscle that is located on the entry point of the gullet into the stomach. This sphincter is a circular, ring-like muscle that acts as a valve - when it is loose, swallowed food and drink can enter into the stomach. When it is taut, the stomach is sealed off from the outside world. the gullet passes through the hole in the diaphragm, a thin sheet of muscle which separates the chest cavity from the abdominal cavity - or, to put it simply, heart and lungs from the stomach, liver, intestines, and other organs of the lower torso.
The diaphragm keeps the said sphincter in place. This entire system works as a one-way valve, as things normally do not go from the stomach back towards the mouth. If, for some reason, this system fails to work properly, content of the stomach can go back to the gullet. This is condition known as acid reflux, heartburn or GERD (gastroesophageal reflux disease).
The stomach secretes hydrochloric acid, or stomach acid. It is a very powerful acid and it is used to break down and dissolve food. This acid is active only in the stomach. What has not been spent during digestion in the stomach gets neutralized when it enters the intestines. Lining of the stomach has been designed to operate in acidic environment and acid cannot harm it. However, if, due to weakened sphincter, acid-rich stomach contents reflux in the gullet, whose lining is not made to withstand acid - there will be problems.
The damage done
Acid irritates the lining of the gullet and causes pain. In some cases, it can lead to inflammation of the lower part of the gullet, and even damage it to a degree that ulcers are formed. In complications, ulcers may bleed, or bleed so much that you end up with anemia. Scars made in the damaged tissue might shrink the gullet to the point that it makes it impossible to swallow, which requires immediate medical intervention.
When it happens
Typically, a weak sphincter cannot withstand increased pressure from the stomach, which is usually related with overeating, drinking too much, laying down, bending over, or similar, and also when there is some pressure on the stomach, that may even come from being overweight. How often reflux happens varies. Most people know what acid reflux is by firsthand, but some people suffer from it regularly, weekly or even daily.