Let me pass on my own IPhone trick, which is probably not an original one, but one I like to think I perfected.
Has there ever been a time that you’ve put your IPhone to sleep and you didn’t hear that locking sound as you hit that button that shuts your phone off? You might have a problem where your phone is stuck in headphone mode, failing to recognize that the headphones have been removed from the corresponding jack.
What to do about it?
Get some toothpicks and some rubbing alcohol. Dip the toothpick end into the alcohol, swabbing it into the jack very gently. Then play with the volume up and down buttons on the side even, and maybe even toggle the ringer on and off a few times.
That should help out any headphone sensor problems you may have immensely.