How to pass variables from a function in functions.php to an other one

get_the_utm_vars doesn’t work like you think it does. A function cannot return more than one value. Right now, when the first return is reached, that value is returned and none of the following lines are ever reached.

You could have get_the_utm_vars return an array of values instead:

function get_the_utm_vars(){
    $utm = array();

    $utm['source']      = htmlspecialchars( $_GET["utm_source"]   ); 
    $utm['medium']      = htmlspecialchars( $_GET["utm_medium"]   ); 
    $utm['term']        = htmlspecialchars( $_GET["utm_term"]     ); 
    $utm['content'] = htmlspecialchars( $_GET["utm_content"]  ); 
    $utm['campaign']    = htmlspecialchars( $_GET["utm_campaign"] ); 

    return $utm;
}

Then you could call get_the_utm_vars to get all of your parameters.

$utm = get_the_utm_vars();
echo $utm['source']; // Will output $_GET["utm_source"]

Regarding your updated function. That could work as well. Whenever you need to access one of those variables within a function, you would need to import it into your scope using global.

function submit_contact_form() {
    global $utm_source, $utm_medium, $utm_term, $utm_content, $utm_campaign;

    // ...
}