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

📄 phpmailer.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 3 页
字号:
            $this->SetError($error);            $this->smtp->Reset();            return false;        }        if(!$this->smtp->Data($header . $body))        {            $this->SetError($this->Lang("data_not_accepted"));            $this->smtp->Reset();            return false;        }        if($this->SMTPKeepAlive == true)            $this->smtp->Reset();        else            $this->SmtpClose();        return true;    }    /**     * Initiates a connection to an SMTP server.  Returns false if the     * operation failed.     * @access private     * @return bool     */    function SmtpConnect() {        if($this->smtp == NULL) { $this->smtp = new SMTP(); }        $this->smtp->do_debug = $this->SMTPDebug;        $hosts = explode(";", $this->Host);        $index = 0;        $connection = ($this->smtp->Connected());        // Retry while there is no connection        while($index < count($hosts) && $connection == false)        {            if(strstr($hosts[$index], ":"))                list($host, $port) = explode(":", $hosts[$index]);            else            {                $host = $hosts[$index];                $port = $this->Port;            }            if($this->smtp->Connect($host, $port, $this->Timeout))            {                if ($this->Helo != '')                    $this->smtp->Hello($this->Helo);                else                    $this->smtp->Hello($this->ServerHostname());                if($this->SMTPAuth)                {                    if(!$this->smtp->Authenticate($this->Username,                                                  $this->Password))                    {                        $this->SetError($this->Lang("authenticate"));                        $this->smtp->Reset();                        $connection = false;                    }                }                $connection = true;            }            $index++;        }        if(!$connection)            $this->SetError($this->Lang("connect_host"));        return $connection;    }    /**     * Closes the active SMTP session if one exists.     * @return void     */    function SmtpClose() {        if($this->smtp != NULL)        {            if($this->smtp->Connected())            {                $this->smtp->Quit();                $this->smtp->Close();            }        }    }    /**     * Sets the language for all class error messages.  Returns false     * if it cannot load the language file.  The default language type     * is English.     * @param string $lang_type Type of language (e.g. Portuguese: "br")     * @param string $lang_path Path to the language file directory     * @access public     * @return bool     */    function SetLanguage($lang_type, $lang_path = "language/") {        if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))            include($lang_path.'phpmailer.lang-'.$lang_type.'.php');        else if(file_exists($lang_path.'phpmailer.lang-en.php'))            include($lang_path.'phpmailer.lang-en.php');        else        {            $this->SetError("Could not load language file");            return false;        }        $this->language = $PHPMAILER_LANG;        return true;    }    /////////////////////////////////////////////////    // MESSAGE CREATION METHODS    /////////////////////////////////////////////////    /**     * Creates recipient headers.     * @access private     * @return string     */    function AddrAppend($type, $addr) {        $addr_str = $type . ": ";        $addr_str .= $this->AddrFormat($addr[0]);        if(count($addr) > 1)        {            for($i = 1; $i < count($addr); $i++)                $addr_str .= ", " . $this->AddrFormat($addr[$i]);        }        $addr_str .= $this->LE;        return $addr_str;    }    /**     * Formats an address correctly.     * @access private     * @return string     */    function AddrFormat($addr) {        if(empty($addr[1]))            $formatted = $addr[0];        else        {            $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .                         $addr[0] . ">";        }        return $formatted;    }    /**     * Wraps message for use with mailers that do not     * automatically perform wrapping and for quoted-printable.     * Original written by philippe.     * @access private     * @return string     */    function WrapText($message, $length, $qp_mode = false) {        $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;        $message = $this->FixEOL($message);        if (substr($message, -1) == $this->LE)            $message = substr($message, 0, -1);        $line = explode($this->LE, $message);        $message = "";        for ($i=0 ;$i < count($line); $i++)        {          $line_part = explode(" ", $line[$i]);          $buf = "";          for ($e = 0; $e<count($line_part); $e++)          {              $word = $line_part[$e];              if ($qp_mode and (strlen($word) > $length))              {                $space_left = $length - strlen($buf) - 1;                if ($e != 0)                {                    if ($space_left > 20)                    {                        $len = $space_left;                        if (substr($word, $len - 1, 1) == "=")                          $len--;                        elseif (substr($word, $len - 2, 1) == "=")                          $len -= 2;                        $part = substr($word, 0, $len);                        $word = substr($word, $len);                        $buf .= " " . $part;                        $message .= $buf . sprintf("=%s", $this->LE);                    }                    else                    {                        $message .= $buf . $soft_break;                    }                    $buf = "";                }                while (strlen($word) > 0)                {                    $len = $length;                    if (substr($word, $len - 1, 1) == "=")                        $len--;                    elseif (substr($word, $len - 2, 1) == "=")                        $len -= 2;                    $part = substr($word, 0, $len);                    $word = substr($word, $len);                    if (strlen($word) > 0)                        $message .= $part . sprintf("=%s", $this->LE);                    else                        $buf = $part;                }              }              else              {                $buf_o = $buf;                $buf .= ($e == 0) ? $word : (" " . $word);                if (strlen($buf) > $length and $buf_o != "")                {                    $message .= $buf_o . $soft_break;                    $buf = $word;                }              }          }          $message .= $buf . $this->LE;        }        return $message;    }    /**     * Set the body wrapping.     * @access private     * @return void     */    function SetWordWrap() {        if($this->WordWrap < 1)            return;        switch($this->message_type)        {           case "alt":              // fall through           case "alt_attachments":              $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);              break;           default:              $this->Body = $this->WrapText($this->Body, $this->WordWrap);              break;        }    }    /**     * Assembles message header.     * @access private     * @return string     */    function CreateHeader() {        $result = "";        // Set the boundaries        $uniq_id = md5(uniqid(time()));        $this->boundary[1] = "b1_" . $uniq_id;        $this->boundary[2] = "b2_" . $uniq_id;        $result .= $this->HeaderLine("Date", $this->RFCDate());        if($this->Sender == "")            $result .= $this->HeaderLine("Return-Path", trim($this->From));        else            $result .= $this->HeaderLine("Return-Path", trim($this->Sender));        // To be created automatically by mail()        if($this->Mailer != "mail")        {            if(count($this->to) > 0)                $result .= $this->AddrAppend("To", $this->to);            else if (count($this->cc) == 0)                $result .= $this->HeaderLine("To", "undisclosed-recipients:;");            if(count($this->cc) > 0)                $result .= $this->AddrAppend("Cc", $this->cc);        }        $from = array();        $from[0][0] = trim($this->From);        $from[0][1] = $this->FromName;        $result .= $this->AddrAppend("From", $from);        // sendmail and mail() extract Bcc from the header before sending        if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))            $result .= $this->AddrAppend("Bcc", $this->bcc);        if(count($this->ReplyTo) > 0)            $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);        // mail() sets the subject itself        if($this->Mailer != "mail")            $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));        $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);        $result .= $this->HeaderLine("X-Priority", $this->Priority);        $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");        if($this->ConfirmReadingTo != "")        {            $result .= $this->HeaderLine("Disposition-Notification-To",                       "<" . trim($this->ConfirmReadingTo) . ">");        }        // Add custom headers        for($index = 0; $index < count($this->CustomHeader); $index++)        {            $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),                       $this->EncodeHeader(trim($this->CustomHeader[$index][1])));        }        $result .= $this->HeaderLine("MIME-Version", "1.0");        switch($this->message_type)        {            case "plain":                $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);                $result .= sprintf("Content-Type: %s; charset=\"%s\"",                                    $this->ContentType, $this->CharSet);                break;            case "attachments":                // fall through            case "alt_attachments":                if($this->InlineImageExists())                {                    $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",                                    "multipart/related", $this->LE, $this->LE,                                    $this->boundary[1], $this->LE);                }                else                {                    $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");                    $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');                }                break;            case "alt":                $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");                $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');                break;        }        if($this->Mailer != "mail")            $result .= $this->LE.$this->LE;        return $result;    }    /**     * Assembles the message body.  Returns an empty string on failure.     * @access private     * @return string     */    function CreateBody() {        $result = "";        $this->SetWordWrap();        switch($this->message_type)        {            case "alt":                $result .= $this->GetBoundary($this->boundary[1], "",                                              "text/plain", "");                $result .= $this->EncodeString($this->AltBody, $this->Encoding);                $result .= $this->LE.$this->LE;                $result .= $this->GetBoundary($this->boundary[1], "",                                              "text/html", "");                $result .= $this->EncodeString($this->Body, $this->Encoding);                $result .= $this->LE.$this->LE;                $result .= $this->EndBoundary($this->boundary[1]);                break;            case "plain":                $result .= $this->EncodeString($this->Body, $this->Encoding);                break;            case "attachments":                $result .= $this->GetBoundary($this->boundary[1], "", "", "");                $result .= $this->EncodeString($this->Body, $this->Encoding);                $result .= $this->LE;                $result .= $this->AttachAll();                break;            case "alt_attachments":                $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);                $result .= sprintf("Content-Type: %s;%s" .                                   "\tboundary=\"%s\"%s",                                   "multipart/alternative", $this->LE,                                   $this->boundary[2], $this->LE.$this->LE);                // Create text body                $result .= $this->GetBoundary($this->boundary[2], "",                                              "text/plain", "") . $this->LE;                $result .= $this->EncodeString($this->AltBody, $this->Encoding);                $result .= $this->LE.$this->LE;                // Create the HTML body                $result .= $this->GetBoundary($this->boundary[2], "",                                              "text/html", "") . $this->LE;                $result .= $this->EncodeString($this->Body, $this->Encoding);                $result .= $this->LE.$this->LE;                $result .= $this->EndBoundary($this->boundary[2]);                $result .= $this->AttachAll();                break;        }        if($this->IsError())            $result = "";        return $result;    }    /**     * Returns the start of a message boundary.     * @access private     */    function GetBoundary($boundary, $charSet, $contentType, $encoding) {        $result = "";        if($charSet == "") { $charSet = $this->CharSet; }        if($contentType == "") { $contentType = $this->ContentType; }        if($encoding == "") { $encoding = $this->Encoding; }        $result .= $this->TextLine("--" . $boundary);        $result .= sprintf("Content-Type: %s; charset = \"%s\"",                            $contentType, $charSet);        $result .= $this->LE;        $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);        $result .= $this->LE;        return $result;    }    /**     * Returns the end of a message boundary.     * @access private     */    function EndBoundary($boundary) {        return $this->LE . "--" . $boundary . "--" . $this->LE;    }    /**     * Sets the message type.     * @access private     * @return void     */    function SetMessageType() {        if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)            $this->message_type = "plain";        else        {            if(count($this->attachment) > 0)                $this->message_type = "attachments";            if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)                $this->message_type = "alt";            if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)                $this->message_type = "alt_attachments";        }    }    /**     * Returns a formatted header line.     * @access private     * @return string     */    function HeaderLine($name, $value) {        return $name . ": " . $value . $this->LE;    }    /**     * Returns a formatted mail line.     * @access private     * @return string     */    function TextLine($value) {        return $value . $this->LE;    }    /////////////////////////////////////////////////    // ATTACHMENT METHODS    /////////////////////////////////////////////////    /**     * Adds an attachment from a path on the filesystem.     * Returns false if the file could not be found     * or accessed.     * @param string $path Path to the attachment.     * @param string $name Overrides the attachment name.     * @param string $encoding File encoding (see $Encoding).     * @param string $type File extension (MIME) type.     * @return bool     */    function AddAttachment($path, $name = "", $encoding = "base64",                           $type = "application/octet-stream") {        if(!@is_file($path))        {            $this->SetError($this->Lang("file_access") . $path);            return false;

⌨️ 快捷键说明

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