Location: PHPKode > projects > pkZoos Website > includes/mail.php
<?php
	if(!defined('PK_MAGIC'))
		die('hack or what?');





	/* */

	class MAIL
	{
		var $lang_id;
		var $filename;
		var $tpl;
		var $headers;





		/* */

		function MAIL()
		{
			$this->reset();
		}





		/* */

		function language($lang_id)
		{
			$this->lang_id = $lang_id;
		}





		/* */

		function filename($filename)
		{
			global $config;

            $this->filename = $filename;

            $this->tpl = new TPL();

            if($this->lang_id != $config['lang_id'])
            {
	            $this->tpl->language($this->lang_id);
            }

            $this->tpl->filename($this->filename, true);
		}





		/* */

		function reset()
		{
			global $config;

			$this->lang_id = $config['lang_id'];
			$this->filename = '';
			$this->tpl = null;
			$this->headers['to'] = array();
			$this->headers['cc'] = array();
			$this->headers['bcc'] = array();
			$this->headers['from'] = '';
			$this->headers['reply_to'] = '';
		}





		/* */

		function header_to($s)
		{
			$this->headers['to'][] = $s;
		}





		/* */

		function header_cc($s)
		{
			$this->headers['cc'][] = $s;
		}





		/* */

		function header_bcc($s)
		{
			$this->headers['bcc'][] = $s;
		}





		/* */

		function header_from($s)
		{
			$this->headers['from'] = $s;
		}





		/* */

		function header_reply_to($s)
		{
			$this->headers['reply_to'] = $s;
		}





		/* */

		function add_var($key, $val)
		{
			$this->tpl->add_var($key, $val);
		}





		/* */

		function add_vars($vars)
		{
			$this->tpl->add_vars($vars);
		}





		/* */

        function add_block_vars($blockname, $vars)
        {
			$this->tpl->add_block_vars($blockname, $vars);
        }





		/* */

		function send()
		{
			$message = $this->tpl->display(true);

			$subject = '';
			$charset = '';

			if(preg_match('#^subject:(.*?)$#im', $message, $match))
			{
				$subject = trim($match[1]);
				$message = trim(preg_replace('#' . preg_quote($match[0], '#') . '[\n]#', '', $message));
			}

			if(preg_match('#^charset:(.*?)$#im', $message, $match))
			{
				$charset = trim($match[1]);
				$message = trim(preg_replace('#' . preg_quote($match[0], '#') . '[\n]#', '', $message));
			}

			$this->headers['to'] = count($this->headers['to']) ? implode(', ', $this->headers['to']) : '';
			$this->headers['cc'] = count($this->headers['cc']) ? implode(', ', $this->headers['cc']) : '';
			$this->headers['bcc'] = count($this->headers['bcc']) ? implode(', ', $this->headers['bcc']) : '';

			$headers = 'Content-Type: text/plain; charset=' . $charset . "\r\n";
			$headers .= $this->headers['cc'] ? 'Cc: ' . $this->headers['cc'] . "\r\n" : '';
			$headers .= $this->headers['bcc'] ? 'Bcc: ' . $this->headers['bcc'] . "\r\n" : '';
			$headers .= $this->headers['from'] ? 'From: ' . $this->headers['from'] . "\r\n" : '';
			$headers .= $this->headers['reply_to'] ? 'Reply-To: ' . $this->headers['reply_to'] . "\r\n" : '';

			@mail($this->headers['to'], $subject, $message, $headers);
		}
	}
?>
Return current item: pkZoos Website