iPhone 4 Stuck on Headphones Mode
I have this problem happen occasionally with many of my audio "gadgets".  I generally follow troubleshooting steps in this order and have always gotten it working again.

Step one is plugging/un-plugging headphones.  This almost always corrects it (but apparently it has not in your case).

Step two is power-cycling the device.  For an iPhone, I would recommend resetting it by holding down both the sleep/wake and home buttons until you see the Apple logo.

Step three is carefully checking the port for damage, or an object that might have become lodged in there.  And if it's not fixed by this point...

Step four is getting it serviced by the manufacturer.  Sometimes problems are simply beyond our ability to fix them ourselves.