Photons are massless, but if $m = 0$ and $E=mc^2$, then $E = 0c^2 = 0$. This would say that photons have no energy, which is not true.
However, given the formula $E = ℎf$, a photon does have energy as $ℎ$ is a non-zero constant and photons with a zero frequency do not exist.
What am I missing here, or does the famous formula not apply to photons?