If the creature is an illegal target as Pharika's Cure tries to resolve, it won't resolve and none of its effects will happen. You won't gain life. If, on the other hand, Pharika's Cure does resolve but the damage is prevented, you'll still gain life.

Artwork
Loading artwork…
Pharika's Cure
Theros · #100 · EN
Nonfoil—Foil—
Card rules
Pharika's Cure deals 2 damage to target creature and you gain 2 life.
"The venom cleanses the sickness from your body, but it will not be pleasant, and you may not survive. Pharika's blessings are fickle." —Solon, acolyte of Pharika
Common · Illustrated by Igor Kieryluk
Format legality
Commander Legal
Duel Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Pauper Legal
Pauper Commander Legal
Penny Legal
Pioneer Legal
Tlr Legal
Vintage Legal
Alchemy Not Legal
Brawl Not Legal
Competitive Brawl Not Legal
Future Not Legal
Gladiator Not Legal
Historic Not Legal
Old School Not Legal
PreDH Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Timeless Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions