Is there a hack for using is_page() within the function.php file?

// You can retrieve your link and get the id (contact ID=4 for example)

$link = $_SERVER['HTTP_REFERER'];
$page_id = url_to_postid($link);

    if (page_id == '4'){
        $subject = "This subject line is for the Contact page.";
    } else {
        $subject = "This subject line is for every other page.";
    }