get_template_directory_uri() not working

Got the problem, Your confirm_email.php function should be inside the scope of wordpress. If you include the file into functions.php file or some file that is inside the wp scope then get_template_directory_uri() function will work.

You can get around the problem by adding the code into a filter or action hook instead of a file. You can try init hook. you can add some parameter in the url to check like http://your_domain.com/?is_email=true and then check it in the code like this:

if($_GET['is_email'] == true){
    // do your stuffs
}

Your solution code might be something like this:

function my_email_function(){
    if(isset($_GET['is_email']) && $_GET['is_email'] == true){
        $temp_dir   = get_template_directory_uri();

        $url        = $temp_dir."/confirm_email.php?id=".$_REQUEST['id']."&key=".$_REQUEST['key'];
        $message    = "Username:".$_REQUEST['name']."Click on below link to confirm your email;".$url;

        $subject    = "Email confirmation Link";
        $headers    = "From: [email protected]" . "\r\n";

        if ( mail( $_REQUEST['email'], $subject, $message, $headers ) ) {
            echo "1";
        } else {
            echo "0";
        }
    }
}
add_action('init', 'my_email_function');