This might be a stupid question, but nonetheless, it has been bothering me.

If you take a photon, make it go through some atoms in a solid, liquid or whatever, then you have the chance of this photon being absorbed by an electron, and thereby exciting the electron. This requires the photon to have enough energy to actually excite the electron to another energy level.

My question is then: How does the photon know if it has enough energy or not? Do they interact very quickly to determine if it's okay or not, or is it just something it "knows?"