Is there anything in the headphone socket which might be fooling the phone? If you can see anything, be very careful how you get it out - try a blower or a soft brush, a hard probe could damage the socket.
(I assume you've already tried rebooting, and that the phone has never got significantly wet since that could damage the socket).