Mass is defined in two different ways in special relativity: one way defines mass ("rest mass" or "invariant mass") as an invariant quantity which is the same for all observers in all reference frames; in the other definition, the measure of mass ("relativistic mass") is dependent on the velocity of the observer.
A so-called massless particle (such as a photon, or a theoretical graviton) moves at the speed of light in every frame of reference. In this case, there is no transformation that will bring the particle to rest. The total energy of such particles becomes smaller and smaller in frames which move faster and faster in the same direction. As such, they have no rest mass, because they can never be measured in a frame where they are at rest. This property of having no rest mass is what causes these particles to be termed "massless." However, even massless particles have a relativistic mass, which varies with their observed energy in various frames of reference.
Basically, stating in a very simplistic way, the m in p=mv is not the rest mass of the photon (which is 0) but the relativistic mass (which is not 0) so the photon has momentum.
In terms of the mass, the momentum of a relativistic particle is defined as
p=γmv where
γ=(1−v2c2)(−12) You can see that a massless particle traveling at c has an ill-defined momentum, according to this formula (zero over zero). But if you take the limit of mass going to zero, with relativistic energy (E=γmc2) held constant, you find precisely that p=Ec, i.e.
that there's a nonzero momentum even when the mass goes to zero.