True, a photon at rest has no mass. Experiments showed, as Einstein predicted, that the light from stars deviates from a straight line as it passes close to the sun. It isn't gravity that does this - it's because the sun's mass is causing a curvature in the fabric of space. A black hole will curve space to the extent that photons become trapped within it.
As Heathfield says, a photon has zero rest mass. But a moving photon does have mass - equivalent to its energy - and it will be affected by gravity.
It is a moot point whether gravity is a real force like electromagnetism. I guess that it isn't. It is probably a pseudo force, like centrifugal force or Coriollis force, caused by curved space.