Amalgum fillings are not affected as the contain no ferromagnetic material
Years ago I used to work with the scientific versions of these in the lab and it was always amusing when newbies would come along, get a little too close and have their credit cards wiped
As gary says, the spin state of atomic nuclei are aligned under the magnetic field pulse and the decay time back to the normal state is measured. This decay time is influenced by different molecular environments, so ultimately (after lots of processing) different tissue/material in the body shows up quite distinctly.