Target creature gets +2/+2 until end of turn. You gain 1 life for each attacking creature you control.
If the target creature becomes an illegal target for Take Heart, the spell doesn’t resolve. You don’t gain life.
You can cast Take Heart even if you control no attacking creatures, perhaps because it’s not even your turn. The target creature gets +2/+2 even though you don’t gain life.