📄 class.phpmailer.php
字号:
* @private
* @returns string
*/
function encode_string ($str, $encoding = "base64") {
switch(strtolower($encoding)) {
case "base64":
// chunk_split is found in PHP >= 3.0.6
$encoded = chunk_split(base64_encode($str));
break;
case "7bit":
case "8bit":
$encoded = $this->fix_eol($str);
if (substr($encoded, -2) != $this->LE)
$encoded .= $this->LE;
break;
case "binary":
$encoded = $str;
break;
case "quoted-printable":
$encoded = $this->encode_qp($str);
break;
default:
$this->error_handler(sprintf("Unknown encoding: %s", $encoding));
return false;
}
return($encoded);
}
/**
* Encode string to quoted-printable. Returns a string.
* @private
* @returns string
*/
function encode_qp ($str) {
$encoded = $this->fix_eol($str);
if (substr($encoded, -2) != $this->LE)
$encoded .= $this->LE;
// Replace every high ascii, control and = characters
$encoded = preg_replace("/([\001-\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->word_wrap($encoded, 74, true);
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.
* @public
* @returns 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.
* @param cid this is the Content Id of the attachment. Use this to identify
* the Id for accessing the image in an HTML form.
* @public
* @returns bool
*/
function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", $type = "application/octet-stream") {
if(!@is_file($path))
{
$this->error_handler(sprintf("Could not access [%s] file", $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 the number of embedded images in an email.
* @private
* @returns int
*/
function EmbeddedImageCount() {
$ret = 0;
for($i = 0; $i < count($this->attachment); $i++)
{
if($this->attachment[$i][6] == "inline")
$ret++;
}
return $ret;
}
/////////////////////////////////////////////////
// MESSAGE RESET METHODS
/////////////////////////////////////////////////
/**
* Clears all recipients assigned in the TO array. Returns void.
* @public
* @returns void
*/
function ClearAddresses() {
$this->to = array();
}
/**
* Clears all recipients assigned in the CC array. Returns void.
* @public
* @returns void
*/
function ClearCCs() {
$this->cc = array();
}
/**
* Clears all recipients assigned in the BCC array. Returns void.
* @public
* @returns void
*/
function ClearBCCs() {
$this->bcc = array();
}
/**
* Clears all recipients assigned in the ReplyTo array. Returns void.
* @public
* @returns void
*/
function ClearReplyTos() {
$this->ReplyTo = array();
}
/**
* Clears all recipients assigned in the TO, CC and BCC
* array. Returns void.
* @public
* @returns void
*/
function ClearAllRecipients() {
$this->to = array();
$this->cc = array();
$this->bcc = array();
}
/**
* Clears all previously set filesystem, string, and binary
* attachments. Returns void.
* @public
* @returns void
*/
function ClearAttachments() {
$this->attachment = array();
}
/**
* Clears all custom headers. Returns void.
* @public
* @returns void
*/
function ClearCustomHeaders() {
$this->CustomHeader = array();
}
/////////////////////////////////////////////////
// MISCELLANEOUS METHODS
/////////////////////////////////////////////////
/**
* Adds the error message to the error container.
* Returns void.
* @private
* @returns void
*/
function error_handler($msg) {
$this->ErrorInfo = $msg;
}
/**
* Returns the proper RFC 822 formatted date. Returns string.
* @private
* @returns string
*/
function rfc_date() {
$tz = date("Z");
$tzs = ($tz < 0) ? "-" : "+";
$tz = abs($tz);
$tz = ($tz/3600)*100 + ($tz%3600)/60;
$date = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
return $date;
}
/**
* Returns received header for message tracing. Returns string.
* @private
* @returns string
*/
function received() {
// Check for vars because they might not exist. Possibly
// write a small retrieval function (that mailer can use too!)
$str = sprintf("Received: from phpmailer ([%s]) by %s " .
"with HTTP;%s\t %s%s",
$this->get_server_var("REMOTE_ADDR"),
$this->get_server_var("SERVER_NAME"),
$this->LE,
$this->rfc_date(),
$this->LE);
return $str;
}
/**
* 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.
* @private
* @returns mixed
*/
function get_server_var($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 "";
}
/**
* Changes every end of line from CR or LF to CRLF. Returns string.
* @private
* @returns string
*/
function fix_eol($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. Returns void.
* @public
* @returns void
*/
function AddCustomHeader($custom_header) {
$this->CustomHeader[] = $custom_header;
}
/**
* Adds all the Microsoft message headers. Returns string.
* @private
* @returns string
*/
function AddMSMailHeaders() {
$MSHeader = "";
if($this->Priority == 1)
$MSPriority = "High";
elseif($this->Priority == 5)
$MSPriority = "Low";
else
$MSPriority = "Medium";
$MSHeader .= sprintf("X-MSMail-Priority: %s%s", $MSPriority, $this->LE);
$MSHeader .= sprintf("Importance: %s%s", $MSPriority, $this->LE);
return($MSHeader);
}
}
/**
* Boundary - MIME message boundary class
* @author Brent R. Matzelle
*/
class Boundary
{
/**
* Sets the boundary ID.
* @private
* @type string
*/
var $ID = 0;
/**
* Sets the boundary Content Type.
* @public
* @type string
*/
var $ContentType = "text/plain";
/**
* Sets the Encoding.
* @public
* @type string
*/
var $Encoding = "";
/**
* Sets an attachment disposition.
* @public
* @type string
*/
var $Disposition = "";
/**
* Sets an attachment file name.
* @public
* @type string
*/
var $FileName = "";
/**
* Sets the Char set.
* @public
* @type string
*/
var $CharSet = "";
/**
* Sets the line endings of the message. Default is "\n";
* @public
* @type string
*/
var $LE = "\n";
/**
* Main constructor.
*/
function Boundary($boundary_id) {
$this->ID = $boundary_id;
}
/**
* Returns the source of the boundary.
* @public
* @returns string
*/
function GetSource($bLineEnding = true) {
$ret = array();
$mime[] = sprintf("--%s%s", $this->ID, $this->LE);
$mime[] = sprintf("Content-Type: %s; charset = \"%s\"%s",
$this->ContentType, $this->CharSet, $this->LE);
//$mime[] = sprintf("Content-Transfer-Encoding: %s%s", $this->Encoding,
// $this->LE);
if(strlen($this->Disposition) > 0)
{
$mime[] = sprintf("Content-Disposition: %s;");
if(strlen($this->FileName) > 0)
$mime[] = sprinf("filename=\"%s\"", $this->$this->FileName);
}
if($bLineEnding)
$mime[] = $this->LE;
return join("", $mime);
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -