Make sure that jack is completely pushed into the phone. When my son used the earphones today, we had the same problem. He pushed the jack in until it stopped and they looked like they were in, but the music was playing out loud. A firmer push into the hole clicked it into place and it worked.
does it play through both the headphones and the speaker when you plug the headphones in? Cause if does then try restoring it. If that doesn’t work then just take it in and they’ll give you a new phone no questions, unless, of course, you are the one who messed up your phone by dropping it or exposing it to water. Then you’re fucked.
Just speculating, your phone might have some setting that decides whether to play with the headphones, or out of the speaker. What type of phone is it?
are you using iPhone compatible headphones? If they aren’t, the jack will not fully insert into the hole and the speakers will continue to play. Make sure the headphone jack is narrow enough to fit into the hole.