How can individual photons have different amounts of energy?

If photon is an elementary particle, how can different photons have different energy, if $E=mc^2$ and all photons have (or don't have) the same mass and the speed of photon is constant shouldn't it mean all photons have the same amount of energy?

-
This is not a duplicate of physics.stackexchange.com/q/3541, but the answer is the same. –  dmckee Jul 31 '14 at 21:25
Not only can individual photons have different energies, the same photon has different energies since energy is reference frame dependent. A photon with a certain energy in a frame of reference will have a different energy in a different frame of reference. Relatively moving observers will not agree on the energy of the same photon. –  Alfred Centauri Jul 31 '14 at 21:33
This question (v2) seems spurred by a confusion between rest/invariant mass and relativistic mass. See e.g. this Phys.SE post, and a couple of paragraphs down on this Wikipedia page. –  Qmechanic Aug 1 '14 at 13:54

$E = mc^2$ is only true for particles at rest (momentum $p = 0$). The full formula is $$E = \sqrt{m^2c^4 + p^2c^2}$$.

In these formulas, $m$ is the rest mass (or just "mass"). Photons don't have mass, so for them the formula becomes $E = pc = \frac{hc}{\lambda} = h\nu$ where $\nu$ is the frequency.

Therefore, the energy of a photon is proportional to its frequency.

-

I know that everyone recognizes $E = mc^2$ as the emblem of relativity, but the expressions is either incomplete or only applies to massive particles (depending on how you understand the $m$ that appears there).

The full and complete expression is $$(mc^2)^2 = E^2 - (pc)^2 \,,$$ where $m$ should be understood to be the invariant rest mass.

This allows you to recover either interpretation of the shorter form for massive particles and $E = pc$ for massless particles.

-
This is the better way to write the equality because it shows that the mass is the square of the energy-momentum 4-vector and therefore invariant. –  Tobias Brandt Jul 31 '14 at 21:57
...although that is completely lost on anyone who actually needs to look up the answer to this question ;) –  Danu Aug 1 '14 at 1:10