Newton's formula is an approximation of how "gravity really works".
We actually still don't know how gravity really works, but we have vastly refined our understanding of it thanks to Einstein's general theory of relativity.
Gravity is simply a measure of curvature of a 4-dimensional manifold we earthlings call space-time. Local concentrations of mass or energy cause the manifold, which is normally "flat" to curve in a 4D dent (hard to picture but easy to see in mathematical terms). We actually don't know WHY it bends, but we have measured the phenomenon with outstanding accuracy (which incidentally has proven the wrongness of Newton's laws as a fundamental explanation of natural phenomena - they are still useful for engineering purposes though so please do learn them). In other words, gravity is simply geometry.
Most of the "curvature" is along the time dimension, but some (1/300,000,000^2 in SI) is along the spatial dimension. Hence the bending of light rays - even if they have no mass, their trajectory follows the curvature component in "ordinary 3D space". And yes, this has been experimentally validated, so it's not just some math-based fantasy.
And by the way, there is really no such thing as "light rays" - that's another useful approximation of something we don't quite fully understand either :)