I have had this problem on my MacBook Pro, and tried EVERYTHING Apple & Forums suggested - SMC reset, PRAM reset. Apple advised me to send it in for servicing. Since it isn't covered by warranty, I didn't want to do that.
If you do not want to pay Apple to fix your MacBook optical sound jack hardware, you can overcome the problem with this procedure I came up with myself, which overcomes the hardware failure caused by the headphone jack optical sensor thinking something is plugged in there when there isn't.
Ironically, this solution requires a jack be inserted into the headphone jack. Annoying, but workable and free.
Obviously when you do want to use the headphones, you must revert this setting.
Hope this helps!
Doug