0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.117.11.13


Current Path : /var/www/oasis/src_old/
Upload File :
Current File : /var/www/oasis/src_old/cmailer.php

<?php

	$main_src_obj=(explode("/",$_SERVER["REQUEST_URI"]));
	$main_src=substr($_SERVER['SCRIPT_FILENAME'],0,strlen($_SERVER['SCRIPT_FILENAME'])-7);
    require_once  $main_src.'/swiftmailer/lib/Swift.php';
    require_once  $main_src.'/swiftmailer/lib/Swift/Message.php';
    require_once  $main_src.'/swiftmailer/lib/Swift/Connection/SMTP.php';

    class CMailer {
    
        function __construct($aarr_mailer_info) {
            
            $this->marr_mailer_info = $aarr_mailer_info;
		   
          //Using Candor  mail server 
		   // $this->mobj_swift       = new Swift(new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS,"salary@ecandor.com","candorsalary123")); // 69.36.242.244      or     10.10.200.99
			 $this->mobj_swift= new Swift(new Swift_Connection_SMTP("smtp.everyone.net",25,'',"vinod@visbin.com","vinod123"));
		   
		  //Using Gmail  mail server 
		   //$this->mobj_swift       = new Swift(new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS,"tarkasoft@gmail.com","tarka123")); // 69.36.242.244      or     10.10.200.99
          
          //Using  tarka soft  mail server 
 		   // $this->mobj_swift       = new Swift(new Swift_Connection_SMTP("smtp.tarkasoft.com",25,"natesha.s@tarkasoft.com","tarka123")); // 69.36.242.244      or     10.10.200.99
          $this->mobj_swift_recp  = new Swift_RecipientList();
                       
       }
       
       public function send_mail() {
            
            # Checking if all the required params are passed
            $larr_mandatory_fields = array(
                                'subject', 
                                'body', 
                                'from' ,
                                'to'
                                );                               
            foreach ($larr_mandatory_fields as $key => $value) {
                if (!array_key_exists($value, $this->marr_mailer_info)) {
                    throw new Exception('Required mailer information not present / need to pass proper format');
                }
            }
            
            # Checking if atleast one value is passed for 'to' address 
            if( !is_array($this->marr_mailer_info['to']) || count($this->marr_mailer_info['to']) < 1 ) {
                throw new Exception('The TO address is invalid / need to pass proper format');
            }
            
            # Checking if 'from' address is passed correctly
            if( !is_array($this->marr_mailer_info['from']) || count($this->marr_mailer_info['from']) != 2 ) {
                throw new Exception('The FROM address is invalid / need to pass proper format');
            }

            $this->subject = $this->marr_mailer_info['subject'];
            $this->body    = $this->marr_mailer_info['body'];
            $this->from    = $this->marr_mailer_info['from'];
            $this->to      = $this->marr_mailer_info['to'];
            
            # Setting the From address of the mail
            $this->mobj_swift_addr  = new Swift_Address($this->from['email'],$this->from['name']);
            
            # Setting To address(es) of the mail
            foreach($this->to as $key => $value) {
                $this->mobj_swift_recp->addTo($value['email'],$value['name']);
            }
            
            # Setting Cc address(es) if any
            if(is_array($this->marr_mailer_info['cc'])) {
                foreach($this->marr_mailer_info['cc'] as $key => $value) {
                    $this->mobj_swift_recp->addCc($value['email'],$value['name']);
                }
            }
            
            # Setting Bcc address(es) if any
            if(is_array($this->marr_mailer_info['bcc'])) {
                foreach($this->marr_mailer_info['bcc'] as $key => $value) {
                    $this->mobj_swift_recp->addBcc($value['email'],$value['name']);
                }
            }        
            
            # If there are Attachments
            if(is_array($this->marr_mailer_info['attachments'])) { 
            
                # creating the swift message instance, setting the subject of the mail            
                $this->swift_msg = new Swift_Message($this->subject);
                
                # message body of the mail
                $this->swift_msg->attach(new Swift_Message_Part($this->body,'text/html'));

                # attachment(s) of the mail
                foreach($this->marr_mailer_info['attachments'] as $key => $value) {
                
                    if( array_key_exists('disposition', $value) && in_array($value['disposition'],array('inline','attachment')) ) {
                        $disposition = $value['disposition'];
                    } else {
                        $disposition = 'attachment';
                    }
                
                    if( isset($value['mime_type']) )  {
                        $this->swift_msg->attach(new Swift_Message_Attachment(new Swift_File("{$value[file_source]}"), "{$value[file_name]}", "{$value[mime_type]}", "base64", "{$disposition}"));
                    } else {
                        $this->swift_msg->attach(new Swift_Message_Attachment(new Swift_File("{$value[file_source]}"), "{$value[file_name]}", "application/octet-stream", "base64", "{$disposition}"));
                    }
                }
                
            } else { 
                   
                # If there are no Attachments 
                $this->swift_msg = new Swift_Message($this->subject, $this->body, 'text/html');
            }
            
            # Setting return-path
            if( array_key_exists('return-path', $this->marr_mailer_info) ) {
                $this->swift_msg->setReturnPath($this->marr_mailer_info['return-path']); 
            }
            
            # Setting reply to
            if( array_key_exists('reply-to', $this->marr_mailer_info) ) {
                $this->swift_msg->setReplyTo($this->marr_mailer_info['reply-to']); 
            }
            
            # Setting read receipt
            if( array_key_exists('read-receipt', $this->marr_mailer_info) ) {
                $this->swift_msg->requestReadReceipt($this->marr_mailer_info['read-receipt']);
            }
            
            # Setting priority of the mail
            if( array_key_exists('priority', $this->marr_mailer_info) ) {
                # You can provide an integer ranging from 1 (High) to 5 (Low) to indicate the priority. PRIORITY_HIGH = 1 , PRIORITY_NORMAL = 3 (default), PRIORITY_LOW = 5
                $this->swift_msg->setPriority($this->marr_mailer_info['priority']); 
            }

            # Sending mail
            $this->mail_recipients_count = $this->mobj_swift->send($this->swift_msg, $this->mobj_swift_recp, $this->mobj_swift_addr);
            return $this->mail_recipients_count ;          
        }

    }
    
   
  
?>