There are a few things to clarify:
When a photon interacts with an atom, three things can happen:
elastic scattering, the photon keeps its energy level and changes angle
inelastic scattering, the photon keeps part of its energy level and changes angle
absorption, the photon gives all its energy to the atom
Now you are talking about absorption, 3., because that is when the photon ceases to exist as photon, transforms all its energy to the kinetic energy of the absorbing electron, and the electron moves to a higher energy level as per QM. This is called excitation.
Now you are asking why photons only get absorbed by atoms that have certain electron configurations.
Now the absorption happens, as per QM, when the probabilities are so that the photons energy level fits most one of the energy level differences between two electron energy levels in the atomic system.
Energy is quantized and atomic systems are built up so, that the electron shells around the nucleus are existing at certain energy levels.
There are gaps between these energy levels, this is why we have atomic spectra.
In chemistry and atomic physics, an electron shell, or a principal energy level, may be thought of as an orbit followed by electrons around an atom's nucleus. The closest shell to the nucleus is called the "1 shell" (also called "K shell"), followed by the "2 shell" (or "L shell"), then the "3 shell" (or "M shell"), and so on farther and farther from the nucleus. The shells correspond with the principal quantum numbers (n = 1, 2, 3, 4 ...) or are labeled alphabetically with letters used in the X-ray notation (K, L, M, …).
Each shell consists of one or more subshells, and each subshell consists of one or more atomic orbitals.
Although it is commonly stated that all the electrons in a shell have the same energy, this is an approximation. However, the electrons in one subshell do have exactly the same level of energy, with later subshells having more energy per electron than earlier ones. This effect is great enough that the energy ranges associated with shells can overlap
Electrons inside the atomic system can move from one energy level to another by absorbing or emitting photons. Now the certain energy levels have gaps between them, and these gaps, or differences between the energy levels are what electrons need as extra energy to move from one energy level to another.
The way electrons gain this extra energy is from absorbing photons (photons' energy transforms into the kinetic energy of the electron).
Now the reason certain frequency photons only get absorbed by certain atoms, is because only certain atoms will have the electron configuration, that will have a certain energy difference between two energy levels.
If the energy of the photon fits this energy level difference between the two electron energy levels (ground and excited state) then the photon will most probably be absorbed by the atomic system as per QM.