If this does not work try Dr.Fone iOS system recovery with no data loss:https://goo.gl/551JZK
Easily learn to fix a iPhone stuck in headphone mode or that shows that a headphone is connected when it is not and prevents you from hearing music being played by your device.