I had this problem with my original iPhone 3G 16GB model. I had purchased this on the day it was released in 2008. Right around the 3.0 firmware, this problem started happening to me, just like it seems to have started happening for many other people here. I had confirmed that it was 100% heat related. Running an app, even Google Maps for a while would cause the phone to switch to headphones without ever plugging headphones into it. If I held it in front of my A/C vent in my car for a few minutes, it would switch back to normal. I could literally repeat this 100% of the time.
I had Applecare on my iPhone 3G and finally got around to bringing it in to my local Apple Store. The person who inspected it stated he had never heard of this problem (like every Apple employee that people have talked to about it so far... does Apple have a database of these problems???). He noted that there were some cracks in the plastic around the headphone jack and dock which I hadn't even noticed. He said they were replacing phones for this known defect and it was covered since it was under warranty. He suggested that although it was being replaced for this problem, whatever was causing the heat related headphone issue would be fixed by getting a new phone. Unfortunately they didn't have any in stock and would have to get one in. Luckily this was a Saturday and they had it in the following Monday so I didn't have to wait very long.
I went in and get the new phone. They swapped the SIM card and I had a brand new blank 16GB iPhone 3G. I got home and restored it from my last backup on my Macbook Pro, synced all of my apps, photos, music, etc. I was very happy as I ran some games that were pretty stressful on the phone for a very long time and the audio never switched to headphones. I thought everything was working well.
About a month or two later, I went to receive a phone call when I felt my iPhone vibrating in my pocket and it was silent. I thought it was just a bad connection, but then I hit the volume control and it said headphones again!!! Arghhhh...
I just got back from the Apple Store. I explained the whole story to the Apple Genius. He said it sounded a lot like something wrong with my backup that caused the problem to carry over to the new phone. I would buy this, except that it didn't have the problem for a month or two after I started using the replacement phone. Regardless, he suggested resetting it to factory defaults while I was there. I agreed because I had just backed it up. He said to try using it without restoring anything for a while and see if the problem still existed. I told him I could reproduce it in less than 5 minutes if it was still going to happen. He agreed to let my try after he restored it. So, after the restore, I had a fresh iPhone 3G with 3.1.3. I went into Google Maps while in the store with it still plugged into the store's Macbook Pro from the restore. I just browsed around the maps for a few minutes and bam, back to headphone mode... I showed him this and he agreed that it didn't appear to be anything with the software. He agreed to replace it for me since it was under Applecare. He said it was quite an odd problem that he hadn't seen before and the chances of it happening twice seemed crazy, but whatever...
So now I am on my second replacement. I am going to KEEP replacing it if it keeps happening. Hopefully the phone I have now will not have this heat/headphone issue, but if it does, it's going back again and Apple can figure this out after I have replaced 3 phones for the same issue.
I'd like very much to get the next iPhone that comes out, but my recent experiences with my iPhone 3G are making me reconsider. At least I will always be sure to get Applecare with the phone.
One interesting side note that I wasn't aware of: The Apple Genius also indicated that my Applecare warranty would be up in another 70 or so days which I was already aware of. He said that I could actually extend it for another year after that. I thought Applecare was a one time thing, but apparently it isn't, at least not for the iPhone. I told him I would probably be getting the next iPhone if it would be out in time and replace this one, but it's good to know it was an option.
I am going to try and cross post this to all the threads I can find related to this problem that are not archived to try and get the message out to Apple. This is clearly a problem but I'm unsure why it is affecting certain people only. My wife has an 8GB iPhone 3G that I bought on the same day as the original 16G, and that has no issues at all. I've asked her several times and she never has that problem.
I wanted to throw a few things out there that are specific to my use of the iPhone 3G that might help narrow down any possible trigger, if there is one. I sync this to both a Macbook Pro and a PC running Windows 7. On the PC I have a universal dock. I use a Belkin FM tuner in my car that specifically only supports the iPod touch and other iPod models, but works with the iPhone except for the warning that it isn't supported and the iPhone suggests switching on airplane mode to prevent interference. I have about 3 pages of apps, over a thousand photos, a few hundred songs, some TV shows, MobileMe email... I use alarms on the clock, I use the camera, I rarely use text messaging at all... I don't have many contacts in my phone...
I can't think of much else. Hopefully if there is some common thread, throwing these things out there will help other people speak up and possibly narrow down what causes this to happen to the hardware (if anything). It might just be defective hardware, who knows. I hope Apple figures it out and actively tries to fix this problem instead of ignoring it or discounting that it is happening to far too few people to be a real problem. How could it happen to me twice with two different phones? It's happened on 66% of my iPhones I have owned. That seems like a lot to me.