Android - How do I toggle headset/headphone mode manually?
This is a hardware problem, but there is an app called toggleheadset2 that has a widget that allows you to override the hardware switch, toggling headset output off/on.
Sounds like a hardware issue to me. You should return the phone to wherever you bought it.
It appears that I can solve the problem by jacking in the headphone, turning off the phone, turning on the phone again, and jacking out/in the headphone a few times slowly.
And yes, it is a hardware problem solved by a hardware solution.