My iPhone thinks it's always docked -- Volume slider disappeared with no audio output EDIT3*

I managed to fix this problem in a risky way, but it worked for me. Read below.



Pin 11 apparently carries out the following function :

11   GND     
If connected to GND the iPhone sends audio signals through pin 3-4
otherwise it uses onboard speaker.


Source

My iPhone is stuck at the function of using an onboard speaker (dock), and only produces sound when connected to a dock or a charging connector. Whenever I take it out, the phone mutes itself except for ringtones.

I am guessing that some switching mechanism is stuck at that setting. Does anyone know if there is a specific pin-like switch that needs to be adjusted to fix this ?

EDIT

I noticed that sound only plays when connected to the charging dock and powered on. Using the cable with no power OR without the dock mutes the phone. If I remove the iPhone from the dock while it's playing music, it continues for a few seconds and then mutes, the music player is still running on play, but with no audio output.

EDIT2

When trying to connect the AppleTV, I found the following evidence that shows how the iPhone thinks the dock is connected.



The iPhone was NOT docked at this time.
I found a method that worked for me. If you're having a problem similar to mine and cleaning the dock did NOT work for you, try this at your own risk.
Disclaimer : This method might permanently damage your iPhone, mine is out of warranty so it wasn't a big deal if I damaged it, I would still need to pay for replacement.

I don't know what may have caused the phone to lock at the docked state, but my first thought is that there is a switch mechanism inside the dock connector. All I did was get a key and jam it there, and rotate it a bit until it got fixed.
Note: If I inserted the key there and did not rotate it, the problem is fixed temporarily until the key is removed. The only way I got rid of the problem completely is to rotate the key and push the pins downward.

If you try to insert the key and remove it, the problem still persists. I had to jam the key in deep and rotate it a few times (gently) to permanently fix this issue.  

Make sure you insert the key in the middle - left part of the dock connector, that's where  pin 11 is located (I think). 



After placing my phone on a dock again, I lost control over the sound. I did the same method with a bit more rotations using the key and now the problem is gone 100%. Not sure how, not sure why, but it worked.



If using a Key seems too risky for you, read below 

Use cotton wool from the end of a qtip (but not the qtip it's too wide to go in) use a nail file or a very thin screw driver to put the cotton wool inside the docking part and gently move back and forth. If you use alcohol even better. 

(PS i tried a lot of compressed air and a toothbrush and it didn't work - the iPhone was about 3 years old so it was filthy inside. The cotton wool came out surprisingly dirty - ie the tooth brush and the compressed air will work if it's a little dirty or there is a little bit of lint - but not if its very dirty.) 

Good luck.