My understanding of perturbation theory has always been that up to second order, we can calculate the energy of a perturbed system with the following formula $$E=E_n^0+\langle n|H'|n\rangle+\sum_{m\neq n}\frac{\langle n|H'|m\rangle \langle m|H'|n\rangle}{E^0_n-E^0_m}\tag{1}$$
However, when dealing with the Frohlich Hamiltonian for electron phonon interactions, My textbook (a quantum approach to Condensed matter physics by Philip Taylor) says we can use perturbation to calculate the energy correction to second order via the following $$E=E_n^0+\langle \phi|H_{e-p}|\phi\rangle +\langle \phi|H_{e-p}(E^0_n-H^0)^{-1}H_{e-p}|\phi\rangle\tag{2}$$ where $H_{e-p}=i\sum_{k,k'}M_{k,k'}(a^{\dagger}_{-q}+a_{q})c^\dagger_kc_{k'}$ and $q=k-k'$ and $\phi$ is the unperturbed state. How do we get from eq 1 to eq 2? Why has the summation been dropped? Does this have something to do with how perturbation theory works in second quantization?