⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.phpmailer.php

📁 通达OA2007SE源代码 非常好的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?
  class phpmailer
  {
    var $Priority = 3;
    var $CharSet = 'GBK';
    var $ContentType = 'text/html';
    var $Encoding = '8bit';
    var $ErrorInfo = '';
    var $From = 'root@localhost';
    var $FromName = 'Root User';
    var $Sender = '';
    var $Subject = '';
    var $Body = '';
    var $AltBody = '';
    var $WordWrap = 0;
    var $Mailer = 'smtp';
    var $Sendmail = '/usr/sbin/sendmail';
    var $PluginDir = '';
    var $Version = '1.73';
    var $ConfirmReadingTo = '';
    var $Hostname = '';
    var $Host = 'localhost';
    var $Port = 25;
    var $Helo = '';
    var $SMTPAuth = false;
    var $Username = '';
    var $Password = '';
    var $Timeout = 10;
    var $SMTPDebug = false;
    var $SMTPKeepAlive = false;
    var $smtp = NULL;
    var $to = array ();
    var $cc = array ();
    var $bcc = array ();
    var $ReplyTo = array ();
    var $attachment = array ();
    var $CustomHeader = array ();
    var $message_type = '';
    var $boundary = array ();
    var $language = array ();
    var $error_count = 0;
    var $LE = '
';
    function ishtml ($bool)
    {
      if (($bool == true))
      {
        $this->ContentType = 'text/html';
      }
      else
      {
        $this->ContentType = 'text/plain';
      }
    }
    function issmtp ()
    {
      $this->Mailer = 'smtp';
    }
    function ismail ()
    {
      $this->Mailer = 'mail';
    }
    function issendmail ()
    {
      $this->Mailer = 'sendmail';
    }
    function isqmail ()
    {
      $this->Sendmail = '/var/qmail/bin/sendmail';
      $this->Mailer = 'sendmail';
    }
    function addaddress ($address, $name = '')
    {
      $cur = count ($this->to);
      $this->to[$cur][0] = trim ($address);
      $this->to[$cur][1] = $name;
    }
    function addcc ($address, $name = '')
    {
      $cur = count ($this->cc);
      $this->cc[$cur][0] = trim ($address);
      $this->cc[$cur][1] = $name;
    }
    function addbcc ($address, $name = '')
    {
      $cur = count ($this->bcc);
      $this->bcc[$cur][0] = trim ($address);
      $this->bcc[$cur][1] = $name;
    }
    function addreplyto ($address, $name = '')
    {
      $cur = count ($this->ReplyTo);
      $this->ReplyTo[$cur][0] = trim ($address);
      $this->ReplyTo[$cur][1] = $name;
    }
    function send ()
    {
      $header = '';
      $body = '';
      $result = true;
      if ((((count ($this->to) + count ($this->cc)) + count ($this->bcc)) < 1))
      {
        $this->SetError ($this->Lang ('provide_address'));
        return false;
      }
      if (!empty ($this->AltBody))
      {
        $this->ContentType = 'multipart/alternative';
      }
      $this->error_count = 0;
      $this->SetMessageType ();
      ($header .= $this->CreateHeader ());
      $body = $this->CreateBody ();
      if (($body == ''))
      {
        return false;
      }
      switch ($this->Mailer)
      {
        case 'sendmail':
        {
          $result = $this->SendmailSend ($header, $body);
          break;
        }
        case 'mail':
        {
          $result = $this->MailSend ($header, $body);
          break;
        }
        case 'smtp':
        {
          $result = $this->SmtpSend ($header, $body);
          break;
        }
        default:
        {
          $this->SetError (($this->Mailer.$this->Lang ('mailer_not_supported')));
          $result = false;
          break;
        }
      }
      return $result;
    }
    function sendmailsend ($header, $body)
    {
      if (($this->Sender != ''))
      {
        $sendmail = sprintf ('%s -oi -f %s -t', $this->Sendmail, $this->Sender);
      }
      else
      {
        $sendmail = sprintf ('%s -oi -t', $this->Sendmail);
      }
      if (!$mail = popen ($sendmail, 'w'))
      {
        $this->SetError (($this->Lang ('execute').$this->Sendmail));
        return false;
      }
      fputs ($mail, $header);
      fputs ($mail, $body);
      $result = ((pclose ($mail) >> 8) & 255);
      if (($result != 0))
      {
        $this->SetError (($this->Lang ('execute').$this->Sendmail));
        return false;
      }
      return true;
    }
    function mailsend ($header, $body)
    {
      $to = '';
      for ($i = 0; ($i < count ($this->to)); ++$i)
      {
        if (($i != 0))
        {
          ($to .= ', ');
        }
        ($to .= $this->to[$i][0]);
      }
      if ((($this->Sender != '') AND (strlen (ini_get ('safe_mode')) < 1)))
      {
        $old_from = ini_get ('sendmail_from');
        ini_set ('sendmail_from', $this->Sender);
        $params = sprintf ('-oi -f %s', $this->Sender);
        $rt = mail ($to, $this->EncodeHeader ($this->Subject), $body, $header, $params);
      }
      else
      {
        $rt = mail ($to, $this->EncodeHeader ($this->Subject), $body, $header);
      }
      if (isset ($old_from))
      {
        ini_set ('sendmail_from', $old_from);
      }
      if (!$rt)
      {
        $this->SetError ($this->Lang ('instantiate'));
        return false;
      }
      return true;
    }
    function smtpsend ($header, $body)
    {
      include_once ($this->PluginDir.'class.smtp.php');
      $error = '';
      $bad_rcpt = array ();
      if (!$this->SmtpConnect ())
      {
        return false;
      }
      $smtp_from = (($this->Sender == '') ? $this->From : $this->Sender);
      if (!$this->smtp->Mail ($smtp_from))
      {
        $error = ($this->Lang ('from_failed').$smtp_from);
        $this->SetError ($error);
        $this->smtp->Reset ();
        return false;
      }
      for ($i = 0; ($i < count ($this->to)); ++$i)
      {
        if (!$this->smtp->Recipient ($this->to[$i][0]))
        {
          $bad_rcpt[] = $this->to[$i][0];
          continue;
        }
      }
      for ($i = 0; ($i < count ($this->cc)); ++$i)
      {
        if (!$this->smtp->Recipient ($this->cc[$i][0]))
        {
          $bad_rcpt[] = $this->cc[$i][0];
          continue;
        }
      }
      for ($i = 0; ($i < count ($this->bcc)); ++$i)
      {
        if (!$this->smtp->Recipient ($this->bcc[$i][0]))
        {
          $bad_rcpt[] = $this->bcc[$i][0];
          continue;
        }
      }
      if ((0 < count ($bad_rcpt)))
      {
        for ($i = 0; ($i < count ($bad_rcpt)); ++$i)
        {
          if (($i != 0))
          {
            ($error .= ', ');
          }
          ($error .= $bad_rcpt[$i]);
        }
        $error = ($this->Lang ('recipients_failed').$error);
        $this->SetError ($error);
        $this->smtp->Reset ();
        return false;
      }
      if (!$this->smtp->Data (($header.$body)))
      {
        $this->SetError ($this->Lang ('data_not_accepted'));
        $this->smtp->Reset ();
        return false;
      }
      if (($this->SMTPKeepAlive == true))
      {
        $this->smtp->Reset ();
      }
      else
      {
        $this->SmtpClose ();
      }
      return true;
    }
    function smtpconnect ()
    {
      if (($this->smtp == NULL))
      {
        $this->smtp = new SMTP ();
      }
      $this->smtp->do_debug = $this->SMTPDebug;
      $hosts = explode (';', $this->Host);
      $index = 0;
      $connection = $this->smtp->Connected ();
      while ((($index < count ($hosts)) AND ($connection == false)))
      {
        if (strstr ($hosts[$index], ':'))
        {
          list ($host, $port) = explode (':', $hosts[$index]);
        }
        else
        {
          $host = $hosts[$index];
          $port = $this->Port;
        }
        if ($this->smtp->Connect ($host, $port, $this->Timeout))
        {
          if (($this->Helo != ''))
          {
            $this->smtp->Hello ($this->Helo);
          }
          else
          {
            $this->smtp->Hello ($this->ServerHostname ());
          }
          if ($this->SMTPAuth)
          {
            if (!$this->smtp->Authenticate ($this->Username, $this->Password))
            {
              $this->SetError ($this->Lang ('authenticate'));
              $this->smtp->Reset ();
              $connection = false;
            }
          }
          $connection = true;
        }
        ++$index;
      }
      if (!$connection)
      {
        $this->SetError ($this->Lang ('connect_host'));
      }
      return $connection;
    }
    function smtpclose ()
    {
      if (($this->smtp != NULL))
      {
        if ($this->smtp->Connected ())
        {
          $this->smtp->Quit ();
          $this->smtp->Close ();
        }
      }
    }
    function setlanguage ($lang_type, $lang_path = 'language/')
    {
      $lang_path1 = str_replace ('\\', '/', '/inc/phpmailer/class.phpmailer.php');
      $lang_path = (substr ($lang_path1, 0, (strrpos ($lang_path1, '/') + 1)).$lang_path);
      if (file_exists (((($lang_path.'phpmailer.lang-').$lang_type).'.php')))
      {
        include ((($lang_path.'phpmailer.lang-').$lang_type).'.php');
      }
      else
      {
        if (file_exists (($lang_path.'phpmailer.lang-en.php')))
        {
          include ($lang_path.'phpmailer.lang-en.php');
        }
        else
        {
          $this->SetError ('Could not load language file');
          return false;
        }
      }
      $this->language = $PHPMAILER_LANG;
      return true;
    }
    function addrappend ($type, $addr)
    {
      $addr_str = ($type.': ');
      ($addr_str .= $this->AddrFormat ($addr[0]));
      if ((1 < count ($addr)))
      {
        for ($i = 1; ($i < count ($addr)); ++$i)
        {
          ($addr_str .= (', '.$this->AddrFormat ($addr[$i])));
        }
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -