<?php
/**
 * IMPORTANT NOTE
 * The code of this system is closed and a private proprietary of Flex Solutions.
 * A written authorization/license from Flex Solutions is required before using or modifying this code.
 * Email: sales@flexsolution.biz, Phone: +962795342585, Website: http://www.flexsolutions.biz
 */
 
class TIDANSMail {

    public static function sendMail($subject, $message, $recipients, $sender=null, $file_paths=null, $cc_email=null) {
	Yii::import('application.extensions.phpmailer.JPhpMailer');
	$mail = new JPhpMailer;
	$mail->IsSMTP();	  // set mailer to use SMTP
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->SMTPSecure = Yii::app()->params["email_SMTPSecure"];
	$mail->Host = Yii::app()->params["email_host"];  // specify main and backup server
	$mail->Port = Yii::app()->params["email_port"];
	$mail->Username = Yii::app()->params["email_user_name"];
	$mail->Password = Yii::app()->params["email_password"];
	$mail->CharSet = 'utf-8';
	$mail->SMTPDebug = 0;

	if ($file_paths != null) {
	    foreach ($file_paths as $file_path) {
		$mail->AddAttachment($file_path);
	    }
	}

	$mail->SetFrom(Yii::app()->params["email_set_from_addres"], "TIDANS System");
	$mail->Subject = $subject;
	$mail->MsgHTML($message);
	if ($recipients != null)
	    $mail->AddAddress($recipients);
	if ($cc_email != null)
	    $mail->AddCC($cc_email);
	try {
	    $mail->Send();
	} catch (Exception $e) {

	}
    }

}

