<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class email extends CI_Class
{
	function __construct()
	{
        parent::__construct();
        $param = $this->db->query("select * from sendmail where active = 1 limit 1")->row_array();
       
			$config = array();
			$config['protocol']     = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
			$config['smtp_host'] = 'ssl://'.$param['domain'];
			$config['smtp_user'] = $param['email'];
			$config['smtp_pass'] = $param['password'];
			$config['smtp_port'] = 465;
		
			$config['mailtype']     = "html";
			
			$config['newline']    = "\r\n";
			$config['wordwrap']     = TRUE;
			$config['validate']     = FALSE;
			
			$this->sendmail->initialize($config);
            $this->setFrom("webmaster@viralpay.cm","VIRALPAY");
			//Load email library
			
			//Send mail
			
	}
    function setSubject($subject = "No title in this mail")
    {
        $this->Subject = $subject;
    }
    function setFrom($mail,$name="")
    {
        $this->From['mail']=$mail;
        $this->From['name']=$name;
    }
    function addAddress($mail,$name="")
    {
        $info['mail']=$mail;
        $info['name']=$name;
        $this->Address[]= $info;
    }
    function send()
    {
        if(!empty($this->Subject) and !empty($this->Address) and !empty($this->Message))
        {
            $this->sendmail->from($this->From['mail'], $this->From['name']);
          
            $to = array_pop($this->Address);
            $this->sendmail->to($to['mail']);
            foreach($this->Address as $add)
            {
                $this->sendmail->cc($add['mail']);
                
            }

			$this->sendmail->subject($this->Subject);
			$this->sendmail->message((($this->Message)));
				
            $this->sendmail->send();
           
        }
        else echo ("Erreur element incomplet pour envoyer un message");
    }
	
}


?>