You won't be able to hear anything through your iPhone's earpiece or use its speakers if your handset gets stuck in headphones mode. Although this won't render your device completely useless, you won't be able to make any calls or play audible media out loud. In the majority of cases, the problem can be fixed relatively easily.
Take a peek inside the headphone socket at the top of your iPhone. If there's dirt and debris lodged down there, the sensor that controls your device's headphones mode may think you have a jack plugged in. Use a needle to remove anything that's clogging up your headphone socket and a couple of squirts of compressed air to clean out whatever's causing your problem. Then, pop the head of a q-tip down your there and give it a twist to make sure you've got everything.
While the technology Apple uses in its iPhones is extremely advanced, it's not immune to the occasional temporary malfunction. The sensor that detects whether or not a pair of headphones are plugged into your device may not have triggered the last time you whipped your headphone jack out of your smartphone. Take your headphone's jack and swiftly insert it in and out of your iPhone's socket a couple of times. This should be enough to correct any sensor errors.
Reboot your device if the problem persists. Hold down the "Home" and "Sleep" buttons on your handset until it restarts. If this proves unsuccessful, you could try restoring your iPhone to its factory settings by connecting it to iTunes and and hitting the "Restore" button under the "Summary" tab. Back up any data and files you want to keep to iTunes or iCloud before doing so. All your personal files will be wiped during the restore process.
If you're unable to get your iPhone out of headphones mode and your device is still under warranty, get in contact with Apple support to arrange for your handset to be repaired or replaced. You'll need to pay to get your device sorted out if your warranty period has expired. Use an authorised Apple service provider if you go down this route. You can find qualified techs by using the service search facility on Apple's website.