With vaccines against drugs of abuse, the drug itself does not cause an immune response. So if a virus attacks you, our immune system is alerted and tries to remove it. But with drugs that is not the case. The vaccines just train the immune system to recognize the drug as foreign and try to remove it. The antibodies are already basically in the body and when you take the drug into the bloodstream they bind to it and stop it from crossing over the blood-brain barrier to get to the reward and pleasure centers.
Article Source:
Houston Chronicle