Google suggests it's caused by some crud interfering with the headphone socket contacts, and can be fixed by cleaning out.
I have some CRC switch cleaner spray, and I've tried moistening a little scrap of cotton and wiping around inside with no effect.
I'm tempted to just spray it straight into the socket. Will this cause damage?
Or does anyone have a better idea?