I believe I know what your question is... but not sure.
Try replacing:
mail("me@domain.com", "the subject", "message",
"From: webmaster@$SERVER_NAME\r\n"
."Reply-To: webmaster@$SERVER_NAME\r\n"
."X-Mailer: PHP/" . phpversion());
with:
mail("me@domain.com", "the subject", "message",
"From: webmaster@" . $_SERVER['SERVER_NAME'] . "\r\n"
."Reply-To: webmaster@" . $SERVER_['SERVER_NAME'] . "\r\n"
."X-Mailer: PHP/" . phpversion());