Hey, hammer ons are a pretty essential part of guitar playing, a great many of good songs use them.

The thing is when I try it it either reduces the volume significantly or mutes the string altogether. So....I'm clearly doing it wrong. What is the technique for doing it correctly and are there any exercises that can help?

It would sound like you aren't fretting correctly.

If you are hammering on a note the force of the finger of the fretting hand hitting the string needs to be enough to make the string vibrate without picking it.

If it is muting the string all together then that means you aren't holding the note down when you hammer on, resulting in a dead note.

Practicing this is pretty simple, just pick two frets on the same string and don't pick either of them. Have your first finger on like fret 2 and use your second or third finger to hammer on and off periodically. Keep it slow, use a metronome. Try and keep the volume of each note as similar as possible.
Like Random3 said, if it is muting the sound entirely, you may be moving your initial finger i.e. if you are doing a hammer on from G to A on the High E string, make sure you keep your finger down on G (3rd fret) before hitting the A (5th Fret). It's suggested to keep that initial finger down before and after the hammer on anyway so once you hit that A, keep your index (or whatever finger is on the 3rd fret) down.

It will take a little bit of time to work up the strength to hit the hammered on notes hard enough to make them ring like your initial picked notes but build up a few lessons that work hammer-ons from each finger (i.e. Index to Middle, Index to Ring, Index to Pinky, Middle to Ring...) and practice to a metronome everyday and you should see progress. While you are practicing, make sure you aren't hammering down so hard that your fingers cause a slight bend. You want to hit them hard enough to make the note ring, but not hard enough that it is changing the note.

While you are practicing your hammer ons, it also makes sense to practice your pull-offs. Pull-offs are actually a bit easier since you can do a slight downward motion when pulling off a note to get it to ring a little bit louder. Do the same finger, to finger approach with pull-offs and incorporate them with your hammer-ons and you'll be playing them cleanly in no time!