If it's working with headsets, clean the headset port. Debris might make your device "think" it's constantly connected to headphones.
Also, use a soft clean brush and clean the charging port, do this cautiously.
Make sure volume is not set to silent, and take a look at the side switch next to the volume buttons. If you see the orange part, it's muted.
If nothing helps, contact Apple Support, or take your iPhone to an Apple Retail Store.