My iPhone thinks my headphones are plugged in?

My iPhone thinks my headphones are plugged in so the speaker is not working.

When I change the volume a screen appears saying that the headphone volume is changing. I can't watch videos or listen to music and when I'm in a call I have to put the phone on speaker.

I've already tried turning it off and on as well as actually plugging in my headphones and taking them back out. Neither worked

Broken socket - or check your headphones maybe a piece stuck in there