That's only the correct equation when you're calculating the energy of something that is sitting still. Light always moves at light speed, so the correct equation in that case is:

E^{2}=(mc^{2})^{2}+(pc)^{2},

where p is momentum. A photon has no mass (m=0), but it has momentum, (p≠0). Therefore, it has energy.