The mechanism of photosensitivity involves the absorption of UV radiation by a drug or its metabolites, resulting in energy release that can damage skin cells. In phototoxicity, the drug absorbs UV light, which causes cellular damage directly. In photoallergy, UV light alters the drug, which then interacts with the immune system, leading to an allergic reaction.