T1 to T4, and T7-T9
Myocardial Infarction pain is thought to originate when visceral sensory nerve endings in the myocardium are irritated and then ascends up the sympathetic trunk and enter the spinal cord through the posterior roots of the upper four Thoracic nerves
(T1-T4) and therefore the pain is felt in the sensory dermatomes supplied by these spinal nerves.
It's believed that there's some spread of sensory neuronal information within the central nervous system because the pain is sometimes felt outside these dermatomes like in the face, jaw, and neck.
In the case of inferior MI, it's assumed that the afferents enter the spinal cord through
T7, T8, T9 spinal roots thereby given referred pain the epigastric dermatomes.
Since both the heart and the thoracic esophagus have similar visceral afferents, we should not be surprised that MI pain and pain from esophagitis may give rise to similar pain syndromes.
Reference:
Clinical Neuroanatomy 7th Edition