Nowhere near enough information to go on, really. If this is a switched socket and the speaker works when it's not connected, then there's either a socket fault or a headphone fault. Try it with another pair of headphones and see if it still happens. If it doesn't, you have faulty headphones. If it does, then you have some sort of a wiring or socket fault.