<?php

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf8' . "\r\n";
    
    // Additional headers
    $headers .= 'From: CC Hellenic <no-replay@homepage.rs>' . "\r\n";
        
    $subject = "Pozivnica za Coca Cola foto konkurs";
    
    $message_noname = "Postovani,
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da da mu pomognete da pobedi u Coca Cola foto konkursu tako
                    sto cete glasati za njega na ovom linku: " . $_POST['additional_data']['url'] . ".
                </p>";
                
    if($_POST['names']['name_1'] && !$_POST['emails']['email_1'])
    {
        echo "Molimo unesite email za prijatelja " . $_POST['names']['name_1'] . ".<br>";
        $error = true;
    }
    if($_POST['names']['name_2'] && !$_POST['emails']['email_2'])
    {
        echo "Molimo unesite email za prijatelja " . $_POST['names']['name_2'] . ".<br>";
        $error = true;
    }
    if($_POST['names']['name_3'] && !$_POST['emails']['email_3'])
    {
        echo "Molimo unesite email za prijatelja " . $_POST['names']['name_3'] . ".<br>";
        $error = true;
    }
    if($_POST['names']['name_4'] && !$_POST['emails']['email_4'])
    {
        echo "Molimo unesite email za prijatelja " . $_POST['names']['name_4'] . ".<br>";
        $error = true;
    }
    if($_POST['names']['name_5'] && !$_POST['emails']['email_5'])
    {
        echo "Molimo unesite email za prijatelja " . $_POST['names']['name_5'] . ".<br>";
        $error = true;
    }

//---------------------------------------------------------------------------------------------------------------------------

if($error == FALSE)
{
    if($_POST['emails']['email_1'])
    {
        if($_POST['names']['name_1'])
        {
            $name = $_POST['names']['name_1'];
                $message = "Postovani " . $name . ",
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da mu pomognete da pobedi u foto konkursu Podeli radost, Coca-Cola, ti i kolega. Glasajte za njega na ovom linku:
                    " . $_POST['additional_data']['url'] . ".
                </p>";
            mail($_POST['emails']['email_1'], $subject, $message, $headers);
            $sent = TRUE;
        }
        else
        {
            mail($_POST['emails']['email_1'], $subject, $message_noname, $headers);
            $sent = TRUE;
        }
    }

//-------------------------------------------------------------------------------------------
    
    if($_POST['emails']['email_2'])
    {
        if($_POST['names']['name_2'])
        {
            $name = $_POST['names']['name_2'];
                $message = "Postovani " . $name . ",
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da mu pomognete da pobedi u foto konkursu Podeli radost, Coca-Cola, ti i kolega. Glasajte za njega na ovom linku:
                    " . $_POST['additional_data']['url'] . ".
                </p>";
            mail($_POST['emails']['email_2'], $subject, $message, $headers);
        }
        else
        {
            mail($_POST['emails']['email_2'], $subject, $message_noname, $headers);
            $sent = TRUE;
        }
    }
//-------------------------------------------------------------------------------------------

    if($_POST['emails']['email_3'])
    {
        if($_POST['names']['name_3'])
        {
            $name = $_POST['names']['name_3'];
                $message = "Postovani " . $name . ",
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da mu pomognete da pobedi u foto konkursu Podeli radost, Coca-Cola, ti i kolega. Glasajte za njega na ovom linku:
                    " . $_POST['additional_data']['url'] . ".
                </p>";
            mail($_POST['emails']['email_3'], $subject, $message, $headers);
            $sent = TRUE;
        }
        else
        {
            mail($_POST['emails']['email_3'], $subject, $message_noname, $headers);
            $sent = TRUE;
        }
    }
//-------------------------------------------------------------------------------------------

    if($_POST['emails']['email_4'])
    {
        if($_POST['names']['name_4'])
        {
            $name = $_POST['names']['name_4'];
                $message = "Postovani " . $name . ",
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da mu pomognete da pobedi u foto konkursu Podeli radost, Coca-Cola, ti i kolega. Glasajte za njega na ovom linku:
                     " . $_POST['additional_data']['url'] . ".
                </p>";
            mail($_POST['emails']['email_4'], $subject, $message, $headers);
            $sent = TRUE;
        }
        else
        {
            mail($_POST['emails']['email_4'], $subject, $message_noname, $headers);
            $sent = TRUE;
        }
    }
//-------------------------------------------------------------------------------------------
    
    if($_POST['emails']['email_5'])
    {
        if($_POST['names']['name_5'])
        {
            $name = $_POST['names']['name_5'];
                $message = "Postovani " . $name . ",
                <p>
                    Prijatelj " . $_POST['additional_data']['from_name'] . " Vas poziva da mu pomognete da pobedi u foto konkursu Podeli radost, Coca-Cola, ti i kolega. Glasajte za njega na ovom linku:
                    " . $_POST['additional_data']['url'] . ".
                </p>";
            mail($_POST['emails']['email_5'], $subject, $message, $headers);
            $sent = TRUE;
        }
        else
        {
            mail($_POST['emails']['email_5'], $subject, $message_noname, $headers);
            $sent = TRUE;
        }
    }
    if(isset($sent)){echo "Pozivnice su poslate<script>$('.popup_close').click(function(){location.reload();});</script>";}else{echo "Molimo popunite bar jedno polje.";}
}
?>