Does a photon need to have EXACTLY the right energy to be absorbed by a gas molecule? From an answer to this question, https://physics.stackexchange.com/questions/281660/how-does-an-electron-absorb-or-emit-light,

Absorption of a photon will occur only when the quantum energy of the photon precisely matches the energy gap between the initial and
final states of the system. (the atom or a molecule as a whole)
i.e., by the absorption of a photon, the system could access to some
higher permissible quantum mechanical energy state. If there is no
pair of energy states such that the photon energy can elevate the
system from the lower to the upper energy state, then the matter will
be transparent to that radiation.

Given that the photon's energy is proportional to the photon's electromagnetic frequency, and that the frequency is subject to tiny Doppler shifts due to differences in velocity between the emitting and absorbing molecules, how can a photon have precisely the same energy as the exact quantum state change for a gas molecule?  Does the photon energy only have to be very close to the quantum state change for a molecule to absorb it?  If so, what happens to the extra(or lesser) energy absorbed by the molecule? Does this margin contribute to the width of observed absorption spectra in radio astronomy?
The Physics SE answer (or the part quoted) was incorrect. The photon does not have to have &quot;precisely&quot; the right energy to cause a transition. The reality is that there is a non-zero probability of causing a transition at all photon energies, but the probability distribution is sharply peaked at the energy we calculate to be the energy difference between the two energy eigenstates of the absorbing atom/molecule.
There are a number of effects that cause this broadening of the frequency response of a bunch of atoms/molecules to photon energy.
The transitions have a &quot;natural width&quot; because the transitions take a finite amount of time. This is encapsulated in a form of the famous uncertainty principle, which means that when viewed over a short time period, there is a fuzziness to energy levels in the atom/molecule. A classical analogy is to try and define the frequency of a damped harmonic oscillator. The larger the damping, the quicker the oscillation dies away and the broader is the continuous frequency spectrum.
Related to this is collisional broadening. Transitions can be interrupted/truncated by collisions, again resulting in a broadened frequency response.
A photon of fixed frequency (note that having a group of photons at fixed frequency is equally impossible, for similar reasons at the emitting end) will encounter atoms/molecules travelling with different velocities and as a result their frequency responses will be Doppler shifted by the appropriate amount.
The application of electromagnetic fields can also broaden and shift the frequency response.