<?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=array('mail_sender'=>config::get('core.mail_sender'),
						  'smtp_host'=>config::get('core.smtp_host'),
						  'smtp_login'=>config::get('core.smtp_login'),
						  'smtp_pass'=>config::get('core.smtp_pass'),
						  'sendmail_path'=>config::get('core.sendmail_path'),
			);
		}
		
		$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));
		}
	}
}