<?php
    class MailSend{
        
        public $mail_array = [];
        private $attachment   = "";
        
        public function Mail(){
            // echo "<pre>";
            // print_r($this->mail_array);
            
            if(is_array($this->mail_array)){
                if(isset($this->mail_array['verif_box']) && md5($this->mail_array['verif_box']).'a4xn' == $_COOKIE['tntcon']){
                   
                    #Sender Name
                    $from_name = $this->mail_array['txt_fromname'];
                
                    #Sender Email
                    $from_email = $this->mail_array['txt_email'];
                    
                    #Recipient Name
                    $to_name = $this->mail_array['txt_recipientname'];
                
                    #Recipient Email
                    $to_email = $this->mail_array['txt_recipientemail'];
                   // $to_email = "salvisaurabh00@gmail.com";
                    #Subject
                    $subject = $this->mail_array['txt_subject']; 
                    
                    #Generate Mail Contecnt
                    foreach ($this->mail_array 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")&&($key!="verif_box")) // 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;
                    
                    if($this->mail_array['txt_form'] == ''){
                        
                        if(SENDMAIL_MODE == 0){
                        
                            //$sendmail = sendmail($from_name, $from_email, $to_name, $to_email, $subject, $text_message, $html_message, $this->attachment, $this->mail_array['txt_email']);
                             $sendmail = sendPHPMail($from_name, $from_email, $to_name, $to_email, $subject, $text_message, $html_message, $this->attachment, $this->mail_array['txt_email']);
                           
                        }
                        
                        // var_dump($sendmail);
                        // die();
                        
                        if($sendmail){
                            $redirect = $this->mail_array['txt_redirect'];
                            $this->showPopup($redirect);
                        }
                    }
                
                }else{
                    $_SESSION['codeerror'] = 'Please enter the correct code';
                    $redirect = $this->mail_array['txt_redirect'];
                    echo "<script>window.location.href='".$redirect."';</script>";
                }
            }
            
        }
        
        public function showPopup($redirect){
            echo "<script>alert('Your Request Has Been Sent !');</script>";
            
            echo "<script>window.location.href='".$redirect."';</script>";
        }
        
    }
?>