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

📄 email.php

📁 集成了投票调查、流量统计、文件上传、留言版、论坛、软件下载、文章赏析、通讯录、网上购物 等板块 管理账户为peilei 密码为800901
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

/*
  $Id: email.php,v 1.4 2002/01/31 21:06:12 uid65040 Exp $

  网络商店 - 吉鑫网络
 http://www.chinaifc.com

Copyright (c) 2001,2003 网络商店

    汗化版权所有吉鑫网络
*/

class email{

  var $html;
  var $text;
  var $output;
  var $html_text;
  var $html_images;
  var $image_types;
  var $build_params;
  var $attachments;
  var $headers;

/***************************************
** Constructor function. Sets the headers
** if supplied.
***************************************/

  function email($headers = array()){

    /***************************************
        ** Initialise some variables.
        ***************************************/

    $this->html_images  = array();
    $this->headers      = array();

    if (EMAIL_LINEFEED == 'CRLF') {
      $this->lf = "\r\n";
    } else {
      $this->lf = "\n";
    }

    /***************************************
    ** If you want the auto load functionality
    ** to find other image/file types, add the
    ** extension and content type here.
    ***************************************/

    $this->image_types = array(
                  'gif'  => 'image/gif',
                  'jpg'  => 'image/jpeg',
                  'jpeg'  => 'image/jpeg',
                  'jpe'  => 'image/jpeg',
                  'bmp'  => 'image/bmp',
                  'png'  => 'image/png',
                  'tif'  => 'image/tiff',
                  'tiff'  => 'image/tiff',
                  'swf'  => 'application/x-shockwave-flash'
                  );

    /***************************************
     ** Set these up
     ***************************************/

    $this->build_params['html_encoding']  = 'quoted-printable';
    $this->build_params['text_encoding']  = '7bit';
    $this->build_params['html_charset']    = 'gb2312';
    $this->build_params['text_charset']    = 'gb2312';
    $this->build_params['text_wrap']    = 998;

    /***************************************
     ** Make sure the MIME version header is first.
     ***************************************/

    $this->headers[] = 'MIME-Version: 1.0';

    foreach($headers as $value){
      if(!empty($value))
        $this->headers[] = $value;
    }
  }

/***************************************
** This function will read a file in
** from a supplied filename and return
** it. This can then be given as the first
** argument of the the functions
** add_html_image() or add_attachment().
***************************************/

  function get_file($filename){

    $return = '';
    if($fp = fopen($filename, 'rb')){
      while(!feof($fp)){
        $return .= fread($fp, 1024);
      }
      fclose($fp);
      return $return;

    }else{
      return FALSE;
    }
  }

/***************************************
** Function for extracting images from
** html source. This function will look
** through the html code supplied by add_html()
** and find any file that ends in one of the
** extensions defined in $obj->image_types.
** If the file exists it will read it in and
** embed it, (not an attachment).
**
** Function contributed by Dan Allen
***************************************/

  function find_html_images($images_dir) {

    // Build the list of image extensions
    while(list($key,) = each($this->image_types))
      $extensions[] = $key;

    preg_match_all('/"([^"]+\.('.implode('|', $extensions).'))"/Ui', $this->html, $images);

    for($i=0; $i<count($images[1]); $i++){
      if(file_exists($images_dir.$images[1][$i])){
        $html_images[] = $images[1][$i];
        $this->html = str_replace($images[1][$i], basename($images[1][$i]), $this->html);
      }
    }

    if(!empty($html_images)){

      // If duplicate images are embedded, they may show up as attachments, so remove them.
      $html_images = array_unique($html_images);
      sort($html_images);
  
      for($i=0; $i<count($html_images); $i++){
        if($image = $this->get_file($images_dir.$html_images[$i])){
          $content_type = $this->image_types[substr($html_images[$i], strrpos($html_images[$i], '.') + 1)];
          $this->add_html_image($image, basename($html_images[$i]), $content_type);
        }
      }
    }
  }

/***************************************
** Adds plain text. Use this function
** when NOT sending html email
***************************************/

  function add_text($text = ''){
    $this->text = $text;
  }

/***************************************
** Adds a html part to the mail.
** Also replaces image names with
** content-id's.
***************************************/

  function add_html($html, $text = NULL, $images_dir = NULL){

    $this->html      = $html;
    $this->html_text  = $text;

    if(isset($images_dir))
      $this->find_html_images($images_dir);
  }

/***************************************
** Adds an image to the list of embedded
** images.
***************************************/

  function add_html_image($file, $name = '', $c_type='application/octet-stream'){
    $this->html_images[] = array(
                    'body'   => $file,
                    'name'   => $name,
                    'c_type' => $c_type,
                    'cid'    => md5(uniqid(time()))
                  );
  }


/***************************************
** Adds a file to the list of attachments.
***************************************/

  function add_attachment($file, $name = '', $c_type='application/octet-stream', $encoding = 'base64'){
    $this->attachments[] = array(
                  'body'    => $file,
                  'name'    => $name,
                  'c_type'  => $c_type,
                  'encoding'  => $encoding
                  );
  }

/***************************************
** Adds a text subpart to a mime_part object
***************************************/

  function &add_text_part(&$obj, $text){

    $params['content_type'] = 'text/plain';
    $params['encoding']     = $this->build_params['text_encoding'];
    $params['charset']      = $this->build_params['text_charset'];
    if(is_object($obj)){
      return $obj->addSubpart($text, $params);
    }else{
      return new mime($text, $params);
    }
  }

/***************************************
** Adds a html subpart to a mime_part object
***************************************/

  function &add_html_part(&$obj){
    $params['content_type'] = 'text/html';
    $params['encoding']     = $this->build_params['html_encoding'];
    $params['charset']      = $this->build_params['html_charset'];
    if(is_object($obj)){
      return $obj->addSubpart($this->html, $params);
    }else{
      return new mime($this->html, $params);
    }
  }

/***************************************
** Starts a message with a mixed part
***************************************/

  function &add_mixed_part(){

    $params['content_type'] = 'multipart/mixed';
    return new mime('', $params);
  }

/***************************************
** Adds an alternative part to a mime_part object
***************************************/

  function &add_alternative_part(&$obj){

    $params['content_type'] = 'multipart/alternative';
    if(is_object($obj)){
      return $obj->addSubpart('', $params);
    }else{
      return new mime('', $params);
    }

⌨️ 快捷键说明

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