The difference ($E_2-E_1$)in electronic energy levels give the energy that the photon would have if the atom were held stationary. If the atom is allowed to recoil, the photon energy will be ($E_2-E_1$) minus the recoil energy.
But the recoil energy is only about $10^{-9}$ of the photon energy, so the reduction in photon energy is pretty negligible!