<?PHP
/* ==================================================================
   MAIL Sending Module
   v.1.0.0
   2003-09-18

   Author: Artur Cieslak
   ================================================================== */

class sendmail {
  var $from="";
  var $replyto="";
  var $xmailer="";
  var $cc="";
  var $bcc="";
  var $contenttype="";
  var $mimeversion="";
  var $message="";
  var $subject="";
  var $sendto="";

  function init() {
    // na razie prosty init skanujący globalne parametry.
    if(isset($GLOBALS["MAIL_FROM"]))
      $this->from = $GLOBALS["MAIL_FROM"];
    else
      $this->from = "WebSync <websync@localhost>";
    if(isset($GLOBALS["MAIL_SEND_TO"]))
      $this->sendto = $GLOBALS["MAIL_SEND_TO"];
    if(isset($GLOBALS["MAIL_REPLY_TO"]))
      $this->replyto = $GLOBALS["MAIL_REPLY_TO"];
    if(isset($GLOBALS["MAIL_XMAILER"])) {
      $this->xmailer = $GLOBALS["MAIL_XMAILER"];
    } else {
      $this->xmailer = "WebSync Server Mail Module v.1.0.0";
    }
    if(isset($GLOBALS["MAIL_CC"]))
      $this->cc = $GLOBALS["MAIL_CC"];
    if(isset($GLOBALS["MAIL_BCC"]))
      $this->bcc = $GLOBALS["MAIL_BCC"];
    if(isset($GLOBALS["MAIL_CONTENT_TYPE"]))
      $this->contenttype = $GLOBALS["MAIL_CONTENT_TYPE"];
    if(isset($GLOBALS["MAIL_MIME_VERSION"]))
      $this->mimeversion = $GLOBALS["MAIL_MIME_VERSION"];
  }

  function AddMessage($str) {
     $nl="";
    if($this->message != "")
      $nl="\r\n";
    $this->message = sprintf("%s%s%s",$this->message,$nl,$str);
  }

  function MailTitle($str) {
    $this->subject = $str;
  }

  function SendTo($str) {
    $this->sendto = $str;
  }

  function AddSendTo($str) {
    $nl="";
    if($this->sendto != "")
      $nl="; ";
    $this->sendto = sprintf("%s%s%s",$this->sendto,$nl,$str);
  }

  function Mail() {
    if($this->sendto == "") return(FALSE);
    $header="";
    if($this->from != "")
      $header  = "From: " . $this->from . "\r\n";
    else
      $header  = "From: WebSync <websync@localhost>\r\n";
    if($this->cc != "")
      $header .= "Cc: " . $this->cc . "\r\n";
    if($this->bcc != "")
      $header .= "Bcc: " . $this->bcc . "\r\n";
    if($this->replyto != "")
      $header .= "Reply-To: " . $this->replyto . "\r\n";
    if($this->xmailer != "")
      $header .= "X-Mailer: " . $this->xmailer . "\r\n";
    if($this->contenttype != "")
      $header .= "Content-type: " . $this->contenttype . "\r\n";
    if($this->mimeversion != "")
      $header .= "MIME-Version: " . $this->mimeversion . "\r\n";

    $res = mail($this->sendto,
                $this->subject,
                $this->message,
                $header);
    return($res);
  }
}
?>