function test_compose_email($project_id, $test_id, $recipients, $action)
{
    $display_generic_info = true;
    $display_generic_url = true;
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=test_detail_page.php&test_id={$test_id}&project_id={$project_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $test_detail = test_get_detail($test_id);
    $test_name = $test_detail[TEST_NAME];
    $status = $test_detail[TEST_STATUS];
    $priority = $test_detail[TEST_PRIORITY];
    $test_area = $test_detail[TEST_AREA_TESTED];
    $test_type = $test_detail[TEST_TESTTYPE];
    $ba_owner = $test_detail[TEST_BA_OWNER];
    $qa_owner = $test_detail[TEST_QA_OWNER];
    $assigned_to = $test_detail[TEST_ASSIGNED_TO];
    $comments = $test_detail[TEST_COMMENTS];
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "status_change":
            $subject = "RTH: {$test_name} - Test Status Change";
            $message = "The test status of {$test_name} has been updated by {$first_name} {$last_name}\r\n" . NEWLINE;
            break;
        case "steps_uploaded":
            $subject = "RTH: {$test_name} - Test Steps Added";
            $message = "Test Steps have been uploaded to {$test_name} by {$first_name} {$last_name}\r\n" . NEWLINE;
            break;
    }
    # Generic link to results page if the $generic_url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view the Test Results:" . NEWLINE;
        $message .= "{$generic_url}\n" . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "Project Name: {$project_name}\r" . NEWLINE;
        $message .= "Test Name: {$test_name}\r" . NEWLINE;
        $message .= "Status: {$status}\r" . NEWLINE;
        $message .= "Priority: {$priority}\r\n\r" . NEWLINE;
        $message .= "Test Area: {$test_name}\r" . NEWLINE;
        $message .= "Test Type: {$test_area}\r" . NEWLINE;
        $message .= "BA Owner: {$ba_owner}\r" . NEWLINE;
        $message .= "QA Owner: {$qa_owner}\r" . NEWLINE;
        $message .= "Assigned To: {$assigned_to}\r" . NEWLINE;
        $message .= "Comments: {$comments}\r\n\r" . NEWLINE;
    }
    email_send($recipients, $subject, $message);
}
$s_tempest_admin = $s_user_properties['tempest_admin'];
$s_project_rights = $s_user_properties['project_rights'];
$s_delete_rights = $s_user_properties['delete_rights'];
$s_email = $s_user_properties['email'];
$project_name = $s_project_properties['project_name'];
$project_id = $s_project_properties['project_id'];
$project_details = project_get_details($project_id);
$s_show_test_input = $project_details[PROJ_SHOW_TEST_INPUT];
$test_id = util_pad_id($s_test_details['test_id']);
$test_version_id = $s_test_details['test_version_id'];
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('test_import_csv_page'));
html_page_header($db, $project_name);
html_print_menu();
$row = test_get_detail($test_id);
$test_name = $row[TEST_NAME];
$test_purpose = $row[TEST_PURPOSE];
//$test_comments   = $row[TEST_COMMENTS];
$ba_owner = $row[TEST_BA_OWNER];
$qa_owner = $row[TEST_QA_OWNER];
$test_type = $row[TEST_TESTTYPE];
$area_tested = $row[TEST_AREA_TESTED];
$test_priority = $row[TEST_PRIORITY];
$manual = $row[TEST_MANUAL];
$automated = $row[TEST_AUTOMATED];
$performance = $row[TEST_LR];
$autopass = $row[TEST_AUTO_PASS];
$assigned_to = $row[TEST_ASSIGNED_TO];
$assigned_by = $row[TEST_ASSIGNED_BY];
$dateassigned = $row[TEST_DATE_ASSIGNED];
if (test_name_exists_with_id($project_id, $testname, $test_id)) {
    error_report_show("test_detail_update_page.php", DUPLICATE_TESTNAME);
}
// set value of $steps XOR $auto to YES
if ($automanu == 'man') {
    $steps = 'YES';
} else {
    if ($automanu == 'auto') {
        $auto = 'YES';
    }
}
// UPDATE TEST
test_update_test($test_id, $test_version_id, $testname, $testpurpose, $testcomments, $testpriority, $teststatus, $testareatested, $testtype, $ba_owner, $qa_owner, $tester, $assigned_to, $assigned_by, $dateassigned, $dateexpcomplete, $dateactcomplete, $duration, $autopass, $steps, $auto, $performance, $email_ba_owner, $email_qa_owner);
# Email the ba owner or qa owner on status change
if ($current_status != $teststatus) {
    $test_detail = test_get_detail($test_id);
    if ($email_ba_owner == 'Y' && $test_detail[TEST_BA_OWNER] != '' && $username != $test_detail[TEST_BA_OWNER]) {
        $send_email = true;
        $owner_array = array($test_detail[TEST_BA_OWNER]);
    }
    if ($email_qa_owner == 'Y' && $test_detail[TEST_QA_OWNER] != '' && $username != $test_detail[TEST_QA_OWNER]) {
        $send_email = true;
        if (is_array($owner_array)) {
            array_push($owner_array, $test_detail[TEST_QA_OWNER]);
        } else {
            $owner_array = array($test_detail[TEST_QA_OWNER]);
        }
    }
}
// Compose message and send email
if ($send_email) {