You've been told wrong. The Planck relation E=hf is universal. It was noticed (first by A. C. Lunn at Chicago, then by deBroglie) that in order for that to be consistent with relativity there must also be another universal relation: p=h/ λ. (Relativity mixes space and time, and also energy and momentum, so that relations in one always require corresponding relations in the other.)
Some important relations that are not universal, that hold only for photons or other particles without rest mass, include λ=c/f, which implies p=hf/c and E=pc.
Mike W.
(published on 11/05/2012)