Have you tried a hard reset? That is hold the power and volume down buttons together (at the same time) for about 30 seconds, until the Apple logo appears. If it's still not working then you are probably gonna want to take it to an Apple store for a diagnostic, this SHOULD be free, but if they detect an issue there may be a cost to fix it, since you are probably out of warranty. If they don't detect a hardware issue then the next step would be a factory reset. It's a PIA, BUT it worth the effort to fix the problem. Worst, WORST case scenario, you can still use the phone, and just take calls on the speaker phone, OR with a Bluetooth headset.