Internal shocks provide a plausible heating mechanism in the jets of gamma-ray bursts ( GRBs ) . Shocks occurring below the jet photosphere are mediated by radiation . It was previously found that radiation mediated shocks ( RMSs ) inside GRB jets are inefficient photon producers , and the photons that mediate the RMS must originate from an earlier stage of the explosion . We show that this conclusion is valid only for non-magnetized jets . RMSs that propagate in moderately magnetized plasma develop a collisionless subshock which locally heats the plasma to a relativistic temperature , and the hot electrons emit copious synchrotron photons inside the RMS . We find that this mechanism is generally effective for mildly relativistic shocks and may be the main source of photons observed in GRBs . We derive a simple analytical formula for the generated photon number per proton , Z , which gives Z = 10 ^ { 5 } - 10 ^ { 6 } , consistent with observations . The photons are initially injected with low energies , well below the observed GRB peak . Their number is controlled by two main factors : ( 1 ) the abundance of electron-positron pairs created in the shock , which is self-consistently calculated , and ( 2 ) the upper limit on the brightness temperature of soft radiation set by induced downscattering . The injected soft photons that survive induced downscattering gain energy in the RMS via bulk Comptonization and shape its nonthermal spectrum .