rendered paste body<?php
#Send E-mails only when really needed!
#################if(iCMS!=1) exit;
class Mail
{
public
$HTML=true,
$from,
$from_adr,
$debug=false,
$text;
private
$chars=array('<','>',';',','),
$to=array(),
$smtp=0,
$to_adr=array(),
$o=false;
#Komenda
function Cmd($c)
{
if(!fwrite($this->o,$c."\r\n")) return false;
if($debug) echo fread($this->o,199)."\r\n";
}
#Nawiąż połączenie SMTP
function __construct($t)
{
global $cfg;
$this->smtp=1;
if($cfg['mailh']==1 && $cfg['mailon']==1)
{
if(!$this->o=fsockopen($cfg['smtp'],$cfg['mailport'],$no,$str,20))
echo 'ERROR: Cannot send e-mail :: '.$str.' ('.$no.')';
#Hello
$this->Cmd('HELO '.$cfg['smtp']);
#Hasło?
if(!empty($cfg['smtpl']))
{
$this->Cmd('AUTH LOGIN');
$this->Cmd(base64_encode($cfg['smtpl']));
$this->Cmd(base64_encode($cfg['smtph']));
}
#Domyślny nadawca
setSender($cfg['doc_title'],$cfg['mail']);
}
}
#Nadawca
function setSender($name,$mail=false)
{
$this->from=str_replace($this->chars,'',$name);
if($mail) $this->from_adr=str_replace($this->chars,'',$mail);
}
#Dodaj adres
function Add($name,$adr)
{
$this->to[]=str_replace($this->chars,'',$name);
$this->to_adr[]=str_replace($this->chars,'',$adr);
}
#Wyślij
function Send($topic,$txt)
{
#Dla SMTP
if($this->smtp)
{
$this->Cmd('MAIL FROM: <'.$this->from_adr.'>');
$this->Cmd('DATA');
$this->Cmd('Subject: '.$topic);
$this->Cmd('From: '.$this->od);
$this->Cmd('To: '.$this->to."\r\n");
$this->Cmd($txt);
if(!$this->Cmd('.')) return false;
}
}
#Rozłącz
function __destruct()
{
$this->Cmd('QUIT');
fclose($this->o);
}
}
?>