Try booting into
Safe Mode, by holding down the Shift key when restarting your Mac. If the problem persists even while in
Safe Mode, then it is a hardware issue. There is a small little micro-switch inside that can fail or get jammed with dirt. If you can't get it to work by using a can of computer cleaner compressed "air" (it's actually butane, IIRC) then you probably need to get a new headphone jack (and the board that it is attached to).
Depending on your model, you can probably just replace the I/O board, following some instructions like the following from iFixit: https://www.ifixit.com/Guide/MacBook+Air+13-Inch+Mid+2011+I-O+Board+Replacement/6364
If you're not the DIY type, then I would look up an authorized repair place from Apple's lookup tool: https://locate.apple.com/
Good Luck, and I hope it is a simple fix!!