gagging at bad smells

What good is the gag reflex?
We smelled a skunk the other night and starting coughing and gagging.
What purpose does this serve biologically?

It keeps you from eating the dead skunk, and informs you that it would be best to go elsewhere. The gagging reflex sometimes gets a bit out of hand, but then so does the pain response to straining a muscle, or getting hit on the head.

Considering how closely related smell and taste are its little wonder they can both produce the same reflex.