In addition ... take a look at things like
Template. Maybe "the body of the e-mail" should be "exactly the output of the script," or ... maybe not. The same techniques that are routinely used to construct web-site pages can also very profitably be used to construct emails.