We get heartburn when stomach acid flows back up into the esophagus, the long tube that connects the stomach with the mouth.  There is a sphincter between the esophagus and the stomach called the lower esophageal sphincter.  It is also called the cardiac sphincter because when it lets acid from the stomach up into the esophagus we get heartburn.