Sounds like a bad connection in the headphone jack on the phone.
Unfortunately, that's a hardware issue. If the phone is still under warranty, I would get in touch with Motorola to get it repaired / replaced. If the phone's no longer under warranty, you can probably find someone who can do the repair much cheaper than Motorola - many years ago when I had a StarTac, I got a quote from Moto for a repair and it was actually more expensive than a new phone!