Has Nothing To Do With Software
Your iPhone is working perfectly fine. You just need to clean out your headphone port becuase it is dirty and is tricking the iPhone into thinking the headphones are plugged in when they're really not. Thus, the headphones work and the speaker does not. Try plugging your headphones in and out about 20 times and blow out your headphone port with an air can. It will be back to normal in no time. Same thing happened to me a while back.
Your iPhone is working perfectly fine. You just need to clean out your headphone port becuase it is dirty and is tricking the iPhone into thinking the headphones are plugged in when they're really not. Thus, the headphones work and the speaker does not. Try plugging your headphones in and out about 20 times and blow out your headphone port with an air can. It will be back to normal in no time. Same thing happened to me a while back.