Gravitational redshift
Another way to think about it involves the concept of mass-energy equivalence (E=mc²). The basic idea is that when photons move into a stronger gravitational field, they gain energy. This gain in energy makes them look bluer. But when they move away from the gravitational field, they lose energy. This loss in energy makes them look redder.