When we calculate the photon polarization sums over amplitudes, $$X=\sum\limits_{r=1}^{2}|\mathcal M_r|^2=\mathcal M_\alpha\mathcal M_\beta^*\sum\limits_{r=1}^{2}\epsilon_r^\alpha\epsilon_r^\beta$$ we find it very helpful that we can simply make a substitution: $$\sum\limits_{r=1}^{2}\epsilon_r^\alpha\epsilon_r^\beta\rightarrow-g^{\alpha\beta}$$
This is due to the equality: $$k^\alpha\mathcal M_\alpha(k)=0$$
Now Franz Mandl and Graham Shaw in their book Quantum Field theory attribute this property as the result of the gauge invariance of QED
Gauge invariance of the theory implies the gauge invariance of the matrix elements, i.e. of the Feynman amplitudes. ...
For any process involving external photons, the Feynman amplitude $\mathcal M$ is of the form$$\mathcal M=\epsilon_{r1}^\alpha(\mathbf k_1)\epsilon_{r2}^\beta(\mathbf k_2)...\mathcal M_{\alpha\beta...}(\mathbf k_1,\mathbf k_2,...),\;\;\;\;\;\;\;\;\;\;(8.30)$$ ...
The polarization vectors are of course gauge dependent. For example, for a free photon, described in a Lorentz gauge by the plane wave$$A^\mu(x)=const.\epsilon_r^\mu(\mathbf k)e^{\pm ikx}$$ THe gauge transformation$$A^\mu(x)\rightarrow A^\mu(x)+\partial^\mu f(x), $$ with $$f(x)=\tilde f(k)e^{\pm ikx}$$implies$$\epsilon_r^\mu(\mathbf k)e^{\pm ikx}\rightarrow [\epsilon_r^\mu(\mathbf k)\pm ik^\mu\tilde f(k)]e^{\pm ik^\mu }$$Invariance of the amplitude (8.30) under this transformation requires$$k_1^\alpha\mathcal M_{\alpha\beta...}(\mathbf k_1,\mathbf k_2,...)=k_2^\beta\mathcal M_{\alpha\beta...}(\mathbf k_1,\mathbf k_2,...)=0,$$i.e. when any external photon polarization vector is replaced by the corresponding four-momentum, the amplitude must vanish.
My question is how to understand the statement "Gauge invariance of the theory implies the gauge invariance of the matrix elements, i.e. of the Feynman amplitudes",
and does "the gauge invariance of the matrix elements" really mean that when we make substitution $A^\mu(x)\rightarrow A^\mu(x)+\partial^\mu f(x)$ in the amplitude $\mathcal M$, it will not change?
I saw in Peskins' book how he spent much argument to prove $k^\alpha\mathcal M_\alpha(k)=0$ using the diagrams, so I wonder whether this argument in Mandl's book is valid.
Anyway, what is the significance of the gauge invariance of QED in this equality $k^\alpha\mathcal M_\alpha(k)=0$?