Iphone 3gs earpiece do not work but speaker work?

My iphone 3gs earpiece does not work, when I answer my phone i can't hear it but when I turn on the speaker and put on my ear I can hear, so I want to know what is the actual cause of this. Where is the source from the iphone that allow me to hear through the earpiece?

It's more than likely a hardware failure. Just to be sure, you could restore your phone. Otherwise, the earpiece speaker needs to be replaced.