I don't know if there's any evidence about the relation to magnesium and cortisol, it's something someone said, it doesn't apply to my case so that makes me think it might not be a true fact!
magnesium and calcium are supposed to help you relax, but it's a case of trial and error because everyones body is different.
i think magnesium can help heart palps, as your adrenals get stronger the anxiety and heart palps will lessen. Try not to take things like anti depressants if i were you, i've taken them for years and they've messed my liver up, they can effect cortisol levels too.
Have you tried magnesium? If it helps, carry on taking it.