A photon is massless but has energy and momentum. It's the mode of an electrodmagnetic field, and you have
$$E=|\vec{q}|c,$$
where ##\vec{q}## is the momentum of the photon.
In relativistic physics you don't need a mass to have a momentum!
Relativistically, the general relationship between energy, momentum, and mass is ##E^2 = (pc)^2 + (mc^2)^2## where p is the magnitude of the momentum. For a photon, m = 0 which gives vanhees71's formula, in different notation.