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

📄 class.phpmailer.php

📁 Easy_Buy是一个在线销售系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
    if(!@is_file($path))
    {
      $this->SetError($this->Lang("file_access") . $path);
      return false;
    }

    $filename = basename($path);
    if($name == "")
    $name = $filename;

    $cur = count($this->attachment);
    $this->attachment[$cur][0] = $path;
    $this->attachment[$cur][1] = $filename;
    $this->attachment[$cur][2] = $name;
    $this->attachment[$cur][3] = $encoding;
    $this->attachment[$cur][4] = $type;
    $this->attachment[$cur][5] = false; // isStringAttachment
    $this->attachment[$cur][6] = "attachment";
    $this->attachment[$cur][7] = 0;

    return true;
  }

  /**
     * Attaches all fs, string, and binary attachments to the message.
     * Returns an empty string on failure.
     * @access private
     * @return string
     */
  function AttachAll() {
    // Return text of body
    $mime = array();

    // Add all attachments
    for($i = 0; $i < count($this->attachment); $i++)
    {
      // Check for string attachment
      $bString = $this->attachment[$i][5];
      if ($bString)
      $string = $this->attachment[$i][0];
      else
      $path = $this->attachment[$i][0];

      $filename    = $this->attachment[$i][1];
      $name        = $this->attachment[$i][2];
      $encoding    = $this->attachment[$i][3];
      $type        = $this->attachment[$i][4];
      $disposition = $this->attachment[$i][6];
      $cid         = $this->attachment[$i][7];

      $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
      $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
      $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);

      if($disposition == "inline")
      $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);

      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
      $disposition, $name, $this->LE.$this->LE);

      // Encode as string attachment
      if($bString)
      {
        $mime[] = $this->EncodeString($string, $encoding);
        if($this->IsError()) { return ""; }
        $mime[] = $this->LE.$this->LE;
      }
      else
      {
        $mime[] = $this->EncodeFile($path, $encoding);
        if($this->IsError()) { return ""; }
        $mime[] = $this->LE.$this->LE;
      }
    }

    $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);

    return join("", $mime);
  }

  /**
     * Encodes attachment in requested format.  Returns an
     * empty string on failure.
     * @access private
     * @return string
     */
  function EncodeFile ($path, $encoding = "base64") {
    if(!@$fd = fopen($path, "rb"))
    {
      $this->SetError($this->Lang("file_open") . $path);
      return "";
    }
    $magic_quotes = get_magic_quotes_runtime();
    set_magic_quotes_runtime(0);
    $file_buffer = fread($fd, filesize($path));
    $file_buffer = $this->EncodeString($file_buffer, $encoding);
    fclose($fd);
    set_magic_quotes_runtime($magic_quotes);

    return $file_buffer;
  }

  /**
     * Encodes string to requested format. Returns an
     * empty string on failure.
     * @access private
     * @return string
     */
  function EncodeString ($str, $encoding = "base64") {
    $encoded = "";
    switch(strtolower($encoding)) {
      case "base64":
      // chunk_split is found in PHP >= 3.0.6
      $encoded = chunk_split(base64_encode($str), 76, $this->LE);
      break;
      case "7bit":
      case "8bit":
      $encoded = $this->FixEOL($str);
      if (substr($encoded, -(strlen($this->LE))) != $this->LE)
      $encoded .= $this->LE;
      break;
      case "binary":
      $encoded = $str;
      break;
      case "quoted-printable":
      $encoded = $this->EncodeQP($str);
      break;
      default:
      $this->SetError($this->Lang("encoding") . $encoding);
      break;
    }
    return $encoded;
  }

  /**
     * Encode a header string to best of Q, B, quoted or none.  
     * @access private
     * @return string
     */
  function EncodeHeader ($str, $position = 'text') {
    $x = 0;

    switch (strtolower($position)) {
      case 'phrase':
      if (!preg_match('/[\200-\377]/', $str)) {
        // Can't use addslashes as we don't know what value has magic_quotes_sybase.
        $encoded = addcslashes($str, "\0..\37\177\\\"");

        if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
        return ($encoded);
        else
        return ("\"$encoded\"");
      }
      $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
      break;
      case 'comment':
      $x = preg_match_all('/[()"]/', $str, $matches);
      // Fall-through
      case 'text':
      default:
      $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
      break;
    }

    if ($x == 0)
    return ($str);

    $maxlen = 75 - 7 - strlen($this->CharSet);
    // Try to select the encoding which should produce the shortest output
    if (strlen($str)/3 < $x) {
      $encoding = 'B';
      $encoded = base64_encode($str);
      $maxlen -= $maxlen % 4;
      $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
    } else {
      $encoding = 'Q';
      $encoded = $this->EncodeQ($str, $position);
      $encoded = $this->WrapText($encoded, $maxlen, true);
      $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
    }

    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
    $encoded = trim(str_replace("\n", $this->LE, $encoded));

    return $encoded;
  }

  /**
     * Encode string to quoted-printable.  
     * @access private
     * @return string
     */
  function EncodeQP ($str) {
    $encoded = $this->FixEOL($str);
    if (substr($encoded, -(strlen($this->LE))) != $this->LE)
    $encoded .= $this->LE;

    // Replace every high ascii, control and = characters
    $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
    "'='.sprintf('%02X', ord('\\1'))", $encoded);
    // Replace every spaces and tabs when it's the last character on a line
    $encoded = preg_replace("/([\011\040])".$this->LE."/e",
    "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);

    // Maximum line length of 76 characters before CRLF (74 + space + '=')
    $encoded = $this->WrapText($encoded, 74, true);

    return $encoded;
  }

  /**
     * Encode string to q encoding.  
     * @access private
     * @return string
     */
  function EncodeQ ($str, $position = "text") {
    // There should not be any EOL in the string
    $encoded = preg_replace("[\r\n]", "", $str);

    switch (strtolower($position)) {
      case "phrase":
      $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
      break;
      case "comment":
      $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
      case "text":
      default:
      // Replace every high ascii, control =, ? and _ characters
      $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
      "'='.sprintf('%02X', ord('\\1'))", $encoded);
      break;
    }

    // Replace every spaces to _ (more readable than =20)
    $encoded = str_replace(" ", "_", $encoded);

    return $encoded;
  }

  /**
     * Adds a string or binary attachment (non-filesystem) to the list.
     * This method can be used to attach ascii or binary data,
     * such as a BLOB record from a database.
     * @param string $string String attachment data.
     * @param string $filename Name of the attachment.
     * @param string $encoding File encoding (see $Encoding).
     * @param string $type File extension (MIME) type.
     * @return void
     */
  function AddStringAttachment($string, $filename, $encoding = "base64",
  $type = "application/octet-stream") {
    // Append to $attachment array
    $cur = count($this->attachment);
    $this->attachment[$cur][0] = $string;
    $this->attachment[$cur][1] = $filename;
    $this->attachment[$cur][2] = $filename;
    $this->attachment[$cur][3] = $encoding;
    $this->attachment[$cur][4] = $type;
    $this->attachment[$cur][5] = true; // isString
    $this->attachment[$cur][6] = "attachment";
    $this->attachment[$cur][7] = 0;
  }

  /**
     * Adds an embedded attachment.  This can include images, sounds, and 
     * just about any other document.  Make sure to set the $type to an 
     * image type.  For JPEG images use "image/jpeg" and for GIF images 
     * use "image/gif".
     * @param string $path Path to the attachment.
     * @param string $cid Content ID of the attachment.  Use this to identify 
     *        the Id for accessing the image in an HTML form.
     * @param string $name Overrides the attachment name.
     * @param string $encoding File encoding (see $Encoding).
     * @param string $type File extension (MIME) type.  
     * @return bool
     */
  function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  $type = "application/octet-stream") {

    if(!@is_file($path))
    {
      $this->SetError($this->Lang("file_access") . $path);
      return false;
    }

    $filename = basename($path);
    if($name == "")
    $name = $filename;

    // Append to $attachment array
    $cur = count($this->attachment);
    $this->attachment[$cur][0] = $path;
    $this->attachment[$cur][1] = $filename;
    $this->attachment[$cur][2] = $name;
    $this->attachment[$cur][3] = $encoding;
    $this->attachment[$cur][4] = $type;
    $this->attachment[$cur][5] = false; // isStringAttachment
    $this->attachment[$cur][6] = "inline";
    $this->attachment[$cur][7] = $cid;

    return true;
  }

  /**
     * Returns true if an inline attachment is present.
     * @access private
     * @return bool
     */
  function InlineImageExists() {
    $result = false;
    for($i = 0; $i < count($this->attachment); $i++)
    {
      if($this->attachment[$i][6] == "inline")
      {
        $result = true;
        break;
      }
    }

    return $result;
  }

  /////////////////////////////////////////////////
  // MESSAGE RESET METHODS
  /////////////////////////////////////////////////

  /**
     * Clears all recipients assigned in the TO array.  Returns void.
     * @return void
     */
  function ClearAddresses() {
    $this->to = array();
  }

  /**
     * Clears all recipients assigned in the CC array.  Returns void.
     * @return void
     */
  function ClearCCs() {
    $this->cc = array();
  }

  /**
     * Clears all recipients assigned in the BCC array.  Returns void.
     * @return void
     */
  function ClearBCCs() {
    $this->bcc = array();
  }

  /**
     * Clears all recipients assigned in the ReplyTo array.  Returns void.
     * @return void
     */
  function ClearReplyTos() {
    $this->ReplyTo = array();
  }

  /**
     * Clears all recipients assigned in the TO, CC and BCC
     * array.  Returns void.
     * @return void
     */
  function ClearAllRecipients() {
    $this->to = array();
    $this->cc = array();
    $this->bcc = array();
  }

  /**
     * Clears all previously set filesystem, string, and binary
     * attachments.  Returns void.
     * @return void
     */
  function ClearAttachments() {
    $this->attachment = array();
  }

  /**
     * Clears all custom headers.  Returns void.
     * @return void
     */
  function ClearCustomHeaders() {
    $this->CustomHeader = array();
  }


  /////////////////////////////////////////////////
  // MISCELLANEOUS METHODS
  /////////////////////////////////////////////////

  /**
     * Adds the error message to the error container.
     * Returns void.
     * @access private
     * @return void
     */
  function SetError($msg) {
    $this->error_count++;
    $this->ErrorInfo = $msg;
  }

  /**
     * Returns the proper RFC 822 formatted date. 
     * @access private
     * @return string
     */
  function RFCDate() {
    $tz = date("Z");
    $tzs = ($tz < 0) ? "-" : "+";
    $tz = abs($tz);
    $tz = ($tz/3600)*100 + ($tz%3600)/60;
    $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);

    return $result;
  }

  /**
     * Returns the appropriate server variable.  Should work with both 
     * PHP 4.1.0+ as well as older versions.  Returns an empty string 
     * if nothing is found.
     * @access private
     * @return mixed
     */
  function ServerVar($varName) {
    global $HTTP_SERVER_VARS;
    global $HTTP_ENV_VARS;

    if(!isset($_SERVER))
    {
      $_SERVER = $HTTP_SERVER_VARS;
      if(!isset($_SERVER["REMOTE_ADDR"]))
      $_SERVER = $HTTP_ENV_VARS; // must be Apache
    }

    if(isset($_SERVER[$varName]))
    return $_SERVER[$varName];
    else
    return "";
  }

  /**
     * Returns the server hostname or 'localhost.localdomain' if unknown.
     * @access private
     * @return string
     */
  function ServerHostname() {
    if ($this->Hostname != "")
    $result = $this->Hostname;
    elseif ($this->ServerVar('SERVER_NAME') != "")
    $result = $this->ServerVar('SERVER_NAME');
    else
    $result = "localhost.localdomain";

    return $result;
  }

  /**
     * Returns a message in the appropriate language.
     * @access private
     * @return string
     */
  function Lang($key) {
    if(count($this->language) < 1)
    $this->SetLanguage("en"); // set the default language

    if(isset($this->language[$key]))
    return $this->language[$key];
    else
    return "Language string failed to load: " . $key;
  }

  /**
     * Returns true if an error occurred.
     * @return bool
     */
  function IsError() {
    return ($this->error_count > 0);
  }

  /**
     * Changes every end of line from CR or LF to CRLF.  
     * @access private
     * @return string
     */
  function FixEOL($str) {
    $str = str_replace("\r\n", "\n", $str);
    $str = str_replace("\r", "\n", $str);
    $str = str_replace("\n", $this->LE, $str);
    return $str;
  }

  /**
     * Adds a custom header. 
     * @return void
     */
  function AddCustomHeader($custom_header) {
    $this->CustomHeader[] = explode(":", $custom_header, 2);
  }
}

?>

⌨️ 快捷键说明

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