Theory of multiphoton ionization: Near-resonance effects in two-photon ionization