iPhone 4 earpiece stops working
This can happen when the contact spring inside the headset jack is loose, cracked or broken, or maybe the plug or jack is just dirty and shorted out.  Perhaps try cleaning/degreasing the plug and then blowing out the jack with compressed air.  If that doesn't work, a visit to the Apple store is in order.

This same problem can happen on different models of other phones as well, any phone that has a headset jack.