?? mime.php
字號:
<?php/** * The Mail_Mime class is used to create MIME E-mail messages * * The Mail_Mime class provides an OO interface to create MIME * enabled email messages. This way you can create emails that * contain plain-text bodies, HTML bodies, attachments, inline * images and specific headers. * * Compatible with PHP versions 4 and 5 * * LICENSE: This LICENSE is in the BSD license style. * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org> * Copyright (c) 2003-2006, PEAR <pear-group@php.net> * All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - Neither the name of the authors, nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * * @category Mail * @package Mail_Mime * @author Richard Heyes <richard@phpguru.org> * @author Tomas V.V. Cox <cox@idecnet.com> * @author Cipriano Groenendal <cipri@php.net> * @author Sean Coates <sean@php.net> * @copyright 2003-2006 PEAR <pear-group@php.net> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version CVS: $Id: mime.php,v 1.81 2007/06/21 19:08:28 cipri Exp $ * @link http://pear.php.net/package/Mail_mime * * This class is based on HTML Mime Mail class from * Richard Heyes <richard@phpguru.org> which was based also * in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> * and Sascha Schumann <sascha@schumann.cx> *//** * require PEAR * * This package depends on PEAR to raise errors. */require_once 'PEAR.php';/** * require Mail_mimePart * * Mail_mimePart contains the code required to * create all the different parts a mail can * consist of. */require_once 'Mail/mimePart.php';/** * The Mail_Mime class provides an OO interface to create MIME * enabled email messages. This way you can create emails that * contain plain-text bodies, HTML bodies, attachments, inline * images and specific headers. * * @category Mail * @package Mail_Mime * @author Richard Heyes <richard@phpguru.org> * @author Tomas V.V. Cox <cox@idecnet.com> * @author Cipriano Groenendal <cipri@php.net> * @author Sean Coates <sean@php.net> * @copyright 2003-2006 PEAR <pear-group@php.net> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: @package_version@ * @link http://pear.php.net/package/Mail_mime */class Mail_mime{ /** * Contains the plain text part of the email * * @var string * @access private */ var $_txtbody; /** * Contains the html part of the email * * @var string * @access private */ var $_htmlbody; /** * contains the mime encoded text * * @var string * @access private */ var $_mime; /** * contains the multipart content * * @var string * @access private */ var $_multipart; /** * list of the attached images * * @var array * @access private */ var $_html_images = array(); /** * list of the attachements * * @var array * @access private */ var $_parts = array(); /** * Build parameters * * @var array * @access private */ var $_build_params = array(); /** * Headers for the mail * * @var array * @access private */ var $_headers = array(); /** * End Of Line sequence (for serialize) * * @var string * @access private */ var $_eol; /** * Constructor function. * * @param string $crlf what type of linebreak to use. * Defaults to "\r\n" * * @return void * * @access public */ function Mail_mime($crlf = "\r\n") { $this->_setEOL($crlf); $this->_build_params = array( 'head_encoding' => 'quoted-printable', 'text_encoding' => '7bit', 'html_encoding' => 'quoted-printable', '7bit_wrap' => 998, 'html_charset' => 'ISO-8859-1', 'text_charset' => 'ISO-8859-1', 'head_charset' => 'ISO-8859-1' ); } /** * wakeup function called by unserialize. It re-sets the EOL constant * * @access private * @return void */ function __wakeup() { $this->_setEOL($this->_eol); } /** * Accessor function to set the body text. Body text is used if * it's not an html mail being sent or else is used to fill the * text/plain part that emails clients who don't support * html should show. * * @param string $data Either a string or * the file name with the contents * @param bool $isfile If true the first param should be treated * as a file name, else as a string (default) * @param bool $append If true the text or file is appended to * the existing body, else the old body is * overwritten * * @return mixed true on success or PEAR_Error object * @access public */ function setTXTBody($data, $isfile = false, $append = false) { if (!$isfile) { if (!$append) { $this->_txtbody = $data; } else { $this->_txtbody .= $data; } } else { $cont = $this->_file2str($data); if (PEAR::isError($cont)) { return $cont; } if (!$append) { $this->_txtbody = $cont; } else { $this->_txtbody .= $cont; } } return true; } /** * Adds a html part to the mail. * * @param string $data either a string or the file name with the * contents * @param bool $isfile a flag that determines whether $data is a * filename, or a string(false, default) * * @return bool true on success * @access public */ function setHTMLBody($data, $isfile = false) { if (!$isfile) { $this->_htmlbody = $data; } else { $cont = $this->_file2str($data); if (PEAR::isError($cont)) { return $cont; } $this->_htmlbody = $cont; } return true; } /** * Adds an image to the list of embedded images. * * @param string $file the image file name OR image data itself * @param string $c_type the content type * @param string $name the filename of the image. * Only used if $file is the image data. * @param bool $isfile whether $file is a filename or not. * Defaults to true * * @return bool true on success * @access public */ function addHTMLImage($file, $c_type='application/octet-stream', $name = '', $isfile = true) { $filedata = ($isfile === true) ? $this->_file2str($file) : $file; if ($isfile === true) { $filename = ($name == '' ? $file : $name); } else { $filename = $name; } if (PEAR::isError($filedata)) { return $filedata; } $this->_html_images[] = array( 'body' => $filedata, 'name' => $filename, 'c_type' => $c_type, 'cid' => md5(uniqid(time())) ); return true; } /** * Adds a file to the list of attachments. * * @param string $file The file name of the file to attach * OR the file contents itself * @param string $c_type The content type * @param string $name The filename of the attachment * Only use if $file is the contents * @param bool $isfile Whether $file is a filename or not * Defaults to true * @param string $encoding The type of encoding to use. * Defaults to base64. * Possible values: 7bit, 8bit, base64, * or quoted-printable. * @param string $disposition The content-disposition of this file * Defaults to attachment. * Possible values: attachment, inline. * @param string $charset The character set used in the filename * of this attachment. * @param string $language The language of the attachment * @param string $location The RFC 2557.4 location of the attachment * * @return mixed true on success or PEAR_Error object * @access public */ function addAttachment($file, $c_type = 'application/octet-stream', $name = '', $isfile = true, $encoding = 'base64', $disposition = 'attachment', $charset = '', $language = '', $location = '') { $filedata = ($isfile === true) ? $this->_file2str($file) : $file; if ($isfile === true) { // Force the name the user supplied, otherwise use $file $filename = (strlen($name)) ? $name : $file; } else { $filename = $name; } if (!strlen($filename)) { $msg = "The supplied filename for the attachment can't be empty"; $err = PEAR::raiseError($msg); return $err; } $filename = basename($filename); if (PEAR::isError($filedata)) { return $filedata; } $this->_parts[] = array( 'body' => $filedata, 'name' => $filename, 'c_type' => $c_type, 'encoding' => $encoding, 'charset' => $charset, 'language' => $language, 'location' => $location, 'disposition' => $disposition
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -