I'd like you to definitely review on my small sample Wordpress theme index.php code.

<?php
/*
Template name: Homepage
*/
get_header();
?>
<?php

    if(isset($_GET['action'])):
        $action = $_GET['action'];
        switch($action){
            case "sendmail": include("sendmail.php"); break;
            case "mailsent" : include("thanks.php"); break;
        }
    else:
?>
    <!-------// Begin Content ---------->
    <?php if (have_posts()): ?>
    <?php while(have_posts()): the_post(); ?>
        <tr>
            <td class="contentarea">
                <h1><?php the_title(); ?></h1>
                <p> <?php the_content(); ?></p>
            </td>
        </tr>
    <?php endwhile; ?>
    <?php else: ?>
        <tr>
            <td class="contentarea">
                <h1>Page not Found!</h1>
                <p>Sorry, you are looking a page that is not here! </p>
                <?php get_search_form(); ?>
            </td>
        </tr>
    <?php endif; ?> 
        <!-------// End Content ----------> 
        <tr>
        <!--begin contact form -->  
            <td class="contactarea" height="200">
                <?php include("contact_area.php"); ?>
            </td>
        <!--end contact form -->     
        </tr>
<?php endif;?>
<?php get_footer(); ?

I wish to turn my if statement above like a function something similar to but I'm not sure how:

        if(action_is_set()){
            then_do_the_action();
        }else {
            //begin content..etc.
        }

It is possible to better structure of my code above??I am still learning both PHP and Wordpress. Please , help. Thanks!!.

You are able to write the function in functions.php underneath the theme.

I do not feel it might be well worth the effort to produce a function action_is_set().

You'd finish track of:

function action_is_set() {
    return isset($_GET['action']);
}

Moving your change to a function inside functions.php might be advantageous however.

That will look something such as:

function do_action() {
    switch($_GET['action']) {
        case 'sendmail':
            include('sendmail.php');
            break;
    }
}

Or get this to current page completely modular by moving this content section to a different include file:

<?php
get_header();

switch($_GET['action']) {
    case 'sendmail':
        include('sendmail.php');
        break;
    case 'mailsent':
        include('thanks.php');
        break;
    default:
        include('content.php');
}

get_footer();
?>

I'm not sure how it goes using the guidelines for WordPress, but it's a sensible practice to possess a default situation inside a switch particularly in a predicament where it might do nothing at all if for example they visited yourdomain.com/?action=blah

Guideline: Never expect they'll use it as being intended always think that someone will attempt to interrupt your code.