Usually this problem is caused by dirt getting into the headphone jack. There are several possible ways to fix this.
1. 1) Pull the battery out while your phone is still on
2) Wait 60 seconds
3) Re-insert the battery and power on the phone
2. Blow into the headphone jack. Compressed air works best.
3. Plug in then unplug a set of headphones a few times
4. 1) Plug in a headset into the jack
2) Open up a media player (either the MP3 player or Pandora)
3) Begin to let the music play.
4) Stop the music from playing after a few seconds
5) Completely exit out of the media application.
6) With the headset still plugged in, wait about 15-30 seconds. (this is so that the media/pandora app task can "fully" stop from running)
7) Unplug the headset.
5. 1) Plug in some headphones
2) Open any media app (music player, pandora, accuradio etc.)
3) Start playing music
4) While music is playing quickly remove and insert the headset into the jack (not too rough so it doesn't break anything) until you hear the music coming out of the speaker
6. 1) Make a call (voicemail worked for me)
2) While on the call insert and remove the headset into the jack until you here the person on the other end
7. Trim the end of a q-tip and clean the jack with rubbing alcohol
If none of the above work, take it to one of your carriers stores and have them replace it.