Recently, my iPhone was having issues. Specifically, it thought headphones were inserted when they weren't. I first noticed the problem as I was typing and didn't hear that familiar "click" that normally accompanies a key press.
I thought I had accidentally toggled the ringer mute button (which I seem to do often), but no, it was set to ring. I inserted some headphones and heard everything - the clicks, music, etc.
I placed a call and tried turning the speaker on and off to no avail. Next, I rebooted the phone. No dice. I connected it to my Mac and performed a sync with iTunes and still, there was no sound.
I reset the phone by holding down the power button and the home button. Still, there was no sound without headphones. At last, I got a can of compressed air and gave a couple of short blasts into the headphone port. That did it! The phone must have been interpreting the junk that had collected in there over the past year as headphones.
A simple solution that, hopefully, will save you some time.