First off, open up a terminal and type:
<enter your password>
sudo gedit /etc/modprobe.d/alsa-base
In the file that pops up, add the following to the end:
options snd-hda-intel model=3stack
(if 3stack doesn't work, then try ‘lenovo' or ‘auto' -- ‘toshiba' doesn' work particularly well!)
save and exit. Now type this into a terminal:
sudo gedit /etc/modprobe.conf
In the blank file that appears, enter the following before saving and exitting:
options snd-hda-intel model=6stack-digout
No reboot. You'll get the comforting sounds of Ubuntu's system as you login, but if you want your headphones to work, you're about half way there. Now type this into a terminal:
In the window that appears, use the arrow keys to move around and press ‘m' on anything with ‘MM' underneath it, and press the up arrow to up the volume. Press ‘Esc' to save and exit.
Not open up your volume control -- make sure nothing is unmuted, and in edit > preferences... make the ‘surround' channel available. Move this up to the max (this helps you control your volume later).
Now you should have fully working sound and headphone support! Your microphone slot should also be supported, though you'll probably want to tweak a few volume settings for your favoured apps!