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

📄 class.phpmailer.php

📁 Download you own three BR
💻 PHP
📖 第 1 页 / 共 4 页
字号:
    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   */  public 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   */  public 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;    $this->attachment[$cur][6] = 'inline';    $this->attachment[$cur][7] = $cid;    return true;  }  /**   * Returns true if an inline attachment is present.   * @access public   * @return bool   */  public function InlineImageExists() {    $result = false;    for($i = 0; $i < count($this->attachment); $i++) {      if($this->attachment[$i][6] == 'inline') {        $result = true;        break;      }    }    return $result;  }  /////////////////////////////////////////////////  // CLASS METHODS, MESSAGE RESET  /////////////////////////////////////////////////  /**   * Clears all recipients assigned in the TO array.  Returns void.   * @return void   */  public function ClearAddresses() {    $this->to = array();  }  /**   * Clears all recipients assigned in the CC array.  Returns void.   * @return void   */  public function ClearCCs() {    $this->cc = array();  }  /**   * Clears all recipients assigned in the BCC array.  Returns void.   * @return void   */  public function ClearBCCs() {    $this->bcc = array();  }  /**   * Clears all recipients assigned in the ReplyTo array.  Returns void.   * @return void   */  public function ClearReplyTos() {    $this->ReplyTo = array();  }  /**   * Clears all recipients assigned in the TO, CC and BCC   * array.  Returns void.   * @return void   */  public function ClearAllRecipients() {    $this->to = array();    $this->cc = array();    $this->bcc = array();  }  /**   * Clears all previously set filesystem, string, and binary   * attachments.  Returns void.   * @return void   */  public function ClearAttachments() {    $this->attachment = array();  }  /**   * Clears all custom headers.  Returns void.   * @return void   */  public function ClearCustomHeaders() {    $this->CustomHeader = array();  }  /////////////////////////////////////////////////  // CLASS METHODS, MISCELLANEOUS  /////////////////////////////////////////////////  /**   * Adds the error message to the error container.   * Returns void.   * @access private   * @return void   */  private function SetError($msg) {    $this->error_count++;    $this->ErrorInfo = $msg;  }  /**   * Returns the proper RFC 822 formatted date.   * @access private   * @return string   */  private static function RFCDate() {    $tz = date('Z');    $tzs = ($tz < 0) ? '-' : '+';    $tz = abs($tz);    $tz = (int)($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 server hostname or 'localhost.localdomain' if unknown.   * @access private   * @return string   */  private function ServerHostname() {    if (!empty($this->Hostname)) {      $result = $this->Hostname;    } elseif (isset($_SERVER['SERVER_NAME'])) {      $result = $_SERVER['SERVER_NAME'];    } else {      $result = "localhost.localdomain";    }    return $result;  }  /**   * Returns a message in the appropriate language.   * @access private   * @return string   */  private 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.   * @access public   * @return bool   */  public function IsError() {    return ($this->error_count > 0);  }  /**   * Changes every end of line from CR or LF to CRLF.   * @access private   * @return string   */  private 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.   * @access public   * @return void   */  public function AddCustomHeader($custom_header) {    $this->CustomHeader[] = explode(':', $custom_header, 2);  }  /**   * Evaluates the message and returns modifications for inline images and backgrounds   * @access public   * @return $message   */  public function MsgHTML($message,$basedir='') {    preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);    if(isset($images[2])) {      foreach($images[2] as $i => $url) {        // do not change urls for absolute images (thanks to corvuscorax)        if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {          $filename = basename($url);          $directory = dirname($url);          ($directory == '.')?$directory='':'';          $cid = 'cid:' . md5($filename);          $fileParts = split("\.", $filename);          $ext = $fileParts[1];          $mimeType = $this->_mime_types($ext);          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }          if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }          $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {            $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);          }        }      }    }    $this->IsHTML(true);    $this->Body = $message;    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));    if ( !empty($textMsg) && empty($this->AltBody) ) {      $this->AltBody = $textMsg;    }    if ( empty($this->AltBody) ) {      $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";    }  }  /**   * Gets the mime type of the embedded or inline image   * @access public   * @return mime type of ext   */  public function _mime_types($ext = '') {    $mimes = array(      'hqx'   =>  'application/mac-binhex40',      'cpt'   =>  'application/mac-compactpro',      'doc'   =>  'application/msword',      'bin'   =>  'application/macbinary',      'dms'   =>  'application/octet-stream',      'lha'   =>  'application/octet-stream',      'lzh'   =>  'application/octet-stream',      'exe'   =>  'application/octet-stream',      'class' =>  'application/octet-stream',      'psd'   =>  'application/octet-stream',      'so'    =>  'application/octet-stream',      'sea'   =>  'application/octet-stream',      'dll'   =>  'application/octet-stream',      'oda'   =>  'application/oda',      'pdf'   =>  'application/pdf',      'ai'    =>  'application/postscript',      'eps'   =>  'application/postscript',      'ps'    =>  'application/postscript',      'smi'   =>  'application/smil',      'smil'  =>  'application/smil',      'mif'   =>  'application/vnd.mif',      'xls'   =>  'application/vnd.ms-excel',      'ppt'   =>  'application/vnd.ms-powerpoint',      'wbxml' =>  'application/vnd.wap.wbxml',      'wmlc'  =>  'application/vnd.wap.wmlc',      'dcr'   =>  'application/x-director',      'dir'   =>  'application/x-director',      'dxr'   =>  'application/x-director',      'dvi'   =>  'application/x-dvi',      'gtar'  =>  'application/x-gtar',      'php'   =>  'application/x-httpd-php',      'php4'  =>  'application/x-httpd-php',      'php3'  =>  'application/x-httpd-php',      'phtml' =>  'application/x-httpd-php',      'phps'  =>  'application/x-httpd-php-source',      'js'    =>  'application/x-javascript',      'swf'   =>  'application/x-shockwave-flash',      'sit'   =>  'application/x-stuffit',      'tar'   =>  'application/x-tar',      'tgz'   =>  'application/x-tar',      'xhtml' =>  'application/xhtml+xml',      'xht'   =>  'application/xhtml+xml',      'zip'   =>  'application/zip',      'mid'   =>  'audio/midi',      'midi'  =>  'audio/midi',      'mpga'  =>  'audio/mpeg',      'mp2'   =>  'audio/mpeg',      'mp3'   =>  'audio/mpeg',      'aif'   =>  'audio/x-aiff',      'aiff'  =>  'audio/x-aiff',      'aifc'  =>  'audio/x-aiff',      'ram'   =>  'audio/x-pn-realaudio',      'rm'    =>  'audio/x-pn-realaudio',      'rpm'   =>  'audio/x-pn-realaudio-plugin',      'ra'    =>  'audio/x-realaudio',      'rv'    =>  'video/vnd.rn-realvideo',      'wav'   =>  'audio/x-wav',      'bmp'   =>  'image/bmp',      'gif'   =>  'image/gif',      'jpeg'  =>  'image/jpeg',      'jpg'   =>  'image/jpeg',      'jpe'   =>  'image/jpeg',      'png'   =>  'image/png',      'tiff'  =>  'image/tiff',      'tif'   =>  'image/tiff',      'css'   =>  'text/css',      'html'  =>  'text/html',      'htm'   =>  'text/html',      'shtml' =>  'text/html',      'txt'   =>  'text/plain',      'text'  =>  'text/plain',      'log'   =>  'text/plain',      'rtx'   =>  'text/richtext',      'rtf'   =>  'text/rtf',      'xml'   =>  'text/xml',      'xsl'   =>  'text/xml',      'mpeg'  =>  'video/mpeg',      'mpg'   =>  'video/mpeg',      'mpe'   =>  'video/mpeg',      'qt'    =>  'video/quicktime',      'mov'   =>  'video/quicktime',      'avi'   =>  'video/x-msvideo',      'movie' =>  'video/x-sgi-movie',      'doc'   =>  'application/msword',      'word'  =>  'application/msword',      'xl'    =>  'application/excel',      'eml'   =>  'message/rfc822'    );    return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];  }  /**   * Set (or reset) Class Objects (variables)   *   * Usage Example:   * $page->set('X-Priority', '3');   *   * @access public   * @param string $name Parameter Name   * @param mixed $value Parameter Value   * NOTE: will not work with arrays, there are no arrays to set/reset   */  public function set ( $name, $value = '' ) {    if ( isset($this->$name) ) {      $this->$name = $value;    } else {      $this->SetError('Cannot set or reset variable ' . $name);      return false;    }  }  /**   * Read a file from a supplied filename and return it.   *   * @access public   * @param string $filename Parameter File Name   */  public function getFile($filename) {    $return = '';    if ($fp = fopen($filename, 'rb')) {      while (!feof($fp)) {        $return .= fread($fp, 1024);      }      fclose($fp);      return $return;    } else {      return false;    }  }  /**   * Strips newlines to prevent header injection.   * @access public   * @param string $str String   * @return string   */  public function SecureHeader($str) {    $str = trim($str);    $str = str_replace("\r", "", $str);    $str = str_replace("\n", "", $str);    return $str;  }  /**   * Set the private key file and password to sign the message.   *   * @access public   * @param string $key_filename Parameter File Name   * @param string $key_pass Password for private key   */  public function Sign($cert_filename, $key_filename, $key_pass) {    $this->sign_cert_file = $cert_filename;    $this->sign_key_file = $key_filename;    $this->sign_key_pass = $key_pass;  }}function smtp_mail ( $sendto_email, $subject, $body, $user_name,$extra_hdrs) {$mail = new PHPMailer();$mail->IsSMTP();                   // send via SMTP$mail->Host = "smtp.163.com"; // SMTP servers$mail->SMTPAuth = true;            // turn on SMTP authentication$mail->Username = "3114578";      // SMTP username     注意:普通邮件认证不需要加 @域名$mail->Password = "13605533784";           // SMTP password$mail->From = "3114578@163.com";         // 发件人邮箱$mail->FromName ="3114578";     // 发件人$mail->CharSet = "GB2312";               // 这里指定字符集!$mail->SMTPDebug = 1;//这是成功或失败返回的数据$mail->Encoding = "base64";$mail->AddAddress($sendto_email,$user_name);     // 收件人邮箱和姓名$mail->IsHTML(true);     // send as HTML        // 邮件主题$mail->Subject = $subject;// 邮件内容$mail->Body = $body;$mail->AltBody ="text/html";$mail->Send();}?>

⌨️ 快捷键说明

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