<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
	// Библиотека для работы с почтой
	require_once(LAB_PATH_KERNEL."/classes/phpmailer/class.PhpMailer.php");

	class Mailer extends PhpMailer
	{
		function __construct($emails, $config=array())
		{
			if (!count($config)) $config=LabConfig::$cfg;
			if (!$config) return false;
			
			$this->CharSet="UTF-8";
			$this->Encoding="quoted-printable";
			
			
			if ($config['mail_sender']=='smtp')
			{
				$this->Mailer="smtp";
				$this->IsSMTP();        // send via SMTP
				$this->Host     = $config['smtp_host']; // SMTP servers
				if ($config['smtp_login'])
				{
					$this->SMTPAuth = true;     // turn on SMTP authentication
					$this->Username = $config['smtp_login'];  // SMTP username
					$this->Password = $config['smtp_pass']; // SMTP password
				}
			}
			elseif($config['mail_sender']=='sendmail')
			{
				$this->IsSendmail();
				$this->Sendmail=$config['sendmail_path'];
			}
			else $this->IsMail();
			
			if (is_array($emails)) foreach($emails as $email=>$name){$this->AddAddress(trim($email), trim($name));}
			else
			{
				$emails=explode(',',$emails);
				foreach($emails as $email) $this->AddAddress(trim($email));
			}
		}
	}