<?php
    require_once("../config.php");
    require_once("../startup.php");
	require_once("sendEmail.php");
	

	#Sender Name
    $from_name = $_POST['txt_name'];

    #Sender Email
    $from_email = $_POST['txt_email'];
    
    #Recipient Name
    $to_name = $_POST['txt_recipientname'];

    #Recipient Email
    $to_email = $_POST['txt_recipientemail'];
    
    #Subject
    $subject = $_POST['txt_subject']; 


		


	foreach ($_POST as $key=>$value) 
	{ 
		if (($key!="btn_submit")&&($key!="txt_form")&&($key!="txt_fromname")&&($key!="txt_fromemail")&&($key!="txt_recipientemail")&&($key!="txt_recipientname")&&($key!="txt_subject")&&($key!="txt_redirect")) // everything except record ID,title,submit 
			{ 
				#Replce prefix of input field name
			    $key_replace = str_replace(array('txt_', 'cmb_', 'sel_'), '', $key);
			    
			    #keep first letter is capital of key
			    $keyval = ucfirst($key_replace);
			    
			    #Email content
				$emailMsg.= "$keyval : $value <BR>";
			}	 
	}
	
	$html_message .= $emailMsg;


	$attachment   = "";
			
	 if($_POST['txt_form'] == ''){
                        
        if(SENDMAIL_MODE == 0){
        
            $sendmail = sendmail($from_name, $from_email, $to_name, $to_email, $subject, $text_message, $html_message, $attachment, $_POST['txt_email']);
            
        }
        
        if($sendmail){
            $redirect = $_POST['txt_redirect'];
            echo "<script>alert('Your Request Has Been Sent !');</script>";
            echo "<script>window.location.href='".$redirect."';</script>";
        }
    }