[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 class.phpmailer.php

Zen Cart 源代码 class.phpmailer.php




下载文件

文件名: class.phpmailer.php
文件类型: PHP文件
文件大小: 41.44 KiB
MD5: 0fac82a29aa033fbc20556a6dd782d7a

class.phpmailer.php - 关闭高亮
  1. <?php
  2. ////////////////////////////////////////////////////
  3. // PHPMailer - PHP email class
  4. //
  5. // Class for sending email using either
  6. // sendmail, PHP mail(), or SMTP.  Methods are
  7. // based upon the standard AspEmail(tm) classes.
  8. //
  9. // Copyright (C) 2001 - 2003  Brent R. Matzelle
  10. //
  11. // License: LGPL, see LICENSE
  12. ////////////////////////////////////////////////////
  13.  
  14. /**
  15.  * PHPMailer - PHP email transport class
  16.  *
  17.  * @package classes
  18.  * @author Brent R. Matzelle
  19.  * @copyright 2001 - 2003 Brent R. Matzelle
  20.  * @version (within Zen Cart) $Id: class.phpmailer.php 19328 2011-08-06 22:53:47Z drbyte $
  21.  * @version Modified for Zen Cart added protocols to enable use with Gmail 2007-09-30 Chuck Redman
  22.  */
  23. /**
  24.  * PHPMailer - PHP email transport class
  25.  *
  26.  * @package classes
  27.  */
  28. class PHPMailer
  29. {
  30.   /////////////////////////////////////////////////
  31.   // PUBLIC VARIABLES
  32.   /////////////////////////////////////////////////
  33.  
  34.   /**
  35.      * Email priority (1 = High, 3 = Normal, 5 = low).
  36.      * @var int
  37.      */
  38.   var $Priority          = 3;
  39.  
  40.   /**
  41.      * Sets the CharSet of the message.
  42.      * @var string
  43.      */
  44.   var $CharSet           = "iso-8859-1";
  45.  
  46.   /**
  47.      * Sets the Content-type of the message.
  48.      * @var string
  49.      */
  50.   var $ContentType        = "text/plain";
  51.  
  52.   /**
  53.      * Sets the Encoding of the message. Options for this are "8bit",
  54.      * "7bit", "binary", "base64", and "quoted-printable".
  55.      * @var string
  56.      */
  57.   var $Encoding          = "8bit";
  58.  
  59.   /**
  60.      * Holds the most recent mailer error message.
  61.      * @var string
  62.      */
  63.   var $ErrorInfo         = "";
  64.  
  65.   /**
  66.      * Sets the From email address for the message.
  67.      * @var string
  68.      */
  69.   var $From               = "root@localhost";
  70.  
  71.   /**
  72.      * Sets the From name of the message.
  73.      * @var string
  74.      */
  75.   var $FromName           = "Root User";
  76.  
  77.   /**
  78.      * Sets the Sender email (Return-Path) of the message.  If not empty,
  79.      * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  80.      * @var string
  81.      */
  82.   var $Sender            = "";
  83.  
  84.   /**
  85.      * Sets the Subject of the message.
  86.      * @var string
  87.      */
  88.   var $Subject           = "";
  89.  
  90.   /**
  91.      * Sets the Body of the message.  This can be either an HTML or text body.
  92.      * If HTML then run IsHTML(true).
  93.      * @var string
  94.      */
  95.   var $Body               = "";
  96.  
  97.   /**
  98.      * Sets the text-only body of the message.  This automatically sets the
  99.      * email to multipart/alternative.  This body can be read by mail
  100.      * clients that do not have HTML email capability such as mutt. Clients
  101.      * that can read HTML will view the normal Body.
  102.      * @var string
  103.      */
  104.   var $AltBody           = "";
  105.  
  106.   /**
  107.      * Sets word wrapping on the body of the message to a given number of
  108.      * characters.
  109.      * @var int
  110.      */
  111.   var $WordWrap          = 0;
  112.  
  113.   /**
  114.      * Method to send mail: ("mail", "sendmail", or "smtp").
  115.      * @var string
  116.      */
  117.   var $Mailer            = "mail";
  118.  
  119.   /**
  120.      * Sets the path of the sendmail program.
  121.      * @var string
  122.      */
  123.   var $Sendmail          = "/usr/sbin/sendmail";
  124.  
  125.   /**
  126.      * Path to PHPMailer plugins.  This is now only useful if the SMTP class
  127.      * is in a different directory than the PHP include path.
  128.      * @var string
  129.      */
  130.   var $PluginDir         = "";
  131.  
  132.   /**
  133.      *  Holds PHPMailer version.
  134.      *  @var string
  135.      */
  136.   var $Version           = "1.73";
  137.  
  138.   /**
  139.      * Sets the email address that a reading confirmation will be sent.
  140.      * @var string
  141.      */
  142.   var $ConfirmReadingTo  = "";
  143.  
  144.   /**
  145.      *  Sets the hostname to use in Message-Id and Received headers
  146.      *  and as default HELO string. If empty, the value returned
  147.      *  by SERVER_NAME is used or 'localhost.localdomain'.
  148.      *  @var string
  149.      */
  150.   var $Hostname          = "";
  151.  
  152.   /////////////////////////////////////////////////
  153.   // SMTP VARIABLES
  154.   /////////////////////////////////////////////////
  155.  
  156.   /**
  157.      *  Sets the SMTP hosts.  All hosts must be separated by a
  158.      *  semicolon.  You can also specify a different port
  159.      *  for each host by using this format: [hostname:port]
  160.      *  (e.g. "smtp1.example.com:25;smtp2.example.com").
  161.      *  Hosts will be tried in order.
  162.      *  @var string
  163.      */
  164.   var $Host        = "localhost";
  165.  
  166.   /**
  167.      *  Sets the default SMTP server port.
  168.      *  @var int
  169.      */
  170.   var $Port        = 25;
  171.  
  172.   /**
  173.    *  Sets the SMTP server socket protocol.
  174.    *  @var string
  175.    *  Added for Gmail support CER.
  176.    */
  177.   var $Protocol = '';
  178.  
  179.   /**
  180.      *  Sets the SMTP HELO of the message (Default is $Hostname).
  181.      *  @var string
  182.      */
  183.   var $Helo        = "";
  184.  
  185.   /**
  186.      *  Sets SMTP authentication. Utilizes the Username and Password variables.
  187.      *  @var bool
  188.      */
  189.   var $SMTPAuth     = false;
  190.  
  191.   /**
  192.      *  Sets SMTP username.
  193.      *  @var string
  194.      */
  195.   var $Username     = "";
  196.  
  197.   /**
  198.      *  Sets SMTP password.
  199.      *  @var string
  200.      */
  201.   var $Password     = "";
  202.  
  203.   /**
  204.      *  Sets the SMTP server timeout in seconds. This function will not
  205.      *  work with the win32 version.
  206.      *  @var int
  207.      */
  208.   var $Timeout      = 10;
  209.  
  210.   /**
  211.      *  Sets SMTP class debugging on or off.
  212.      *  @var bool
  213.      */
  214.   var $SMTPDebug    = false;
  215.  
  216.   /**
  217.      * Prevents the SMTP connection from being closed after each mail
  218.      * sending.  If this is set to true then to close the connection
  219.      * requires an explicit call to SmtpClose().
  220.      * @var bool
  221.      */
  222.   var $SMTPKeepAlive = false;
  223.  
  224.   /**#@+
  225.   * @access private
  226.   */
  227.   var $smtp            = NULL;
  228.   var $to              = array();
  229.   var $cc              = array();
  230.   var $bcc             = array();
  231.   var $ReplyTo         = array();
  232.   var $attachment      = array();
  233.   var $CustomHeader    = array();
  234.   var $message_type    = "";
  235.   var $boundary        = array();
  236.   var $language        = array();
  237.   var $error_count     = 0;
  238.   var $LE              = "\n";
  239.   /**#@-*/
  240.  
  241.   /////////////////////////////////////////////////
  242.   // VARIABLE METHODS
  243.   /////////////////////////////////////////////////
  244.  
  245.   /**
  246.      * Sets message type to HTML.
  247.      * @param bool $bool
  248.      * @return void
  249.      */
  250.   function IsHTML($bool) {
  251.     if($bool == true)
  252.     $this->ContentType = "text/html";
  253.     else
  254.     $this->ContentType = "text/plain";
  255.   }
  256.  
  257.   /**
  258.      * Sets Mailer to send message using SMTP.
  259.      * @return void
  260.      */
  261.   function IsSMTP() {
  262.     $this->Mailer = "smtp";
  263.   }
  264.  
  265.   /**
  266.      * Sets Mailer to send message using PHP mail() function.
  267.      * @return void
  268.      */
  269.   function IsMail() {
  270.     $this->Mailer = "mail";
  271.   }
  272.  
  273.   /**
  274.      * Sets Mailer to send message using the $Sendmail program.
  275.      * @return void
  276.      */
  277.   function IsSendmail() {
  278.     $this->Mailer = "sendmail";
  279.   }
  280.  
  281.   /**
  282.      * Sets Mailer to send message using the qmail MTA.
  283.      * @return void
  284.      */
  285.   function IsQmail() {
  286.     $this->Sendmail = "/var/qmail/bin/sendmail";
  287.     $this->Mailer = "sendmail";
  288.   }
  289.  
  290.  
  291.   /////////////////////////////////////////////////
  292.   // RECIPIENT METHODS
  293.   /////////////////////////////////////////////////
  294.  
  295.   /**
  296.      * Adds a "To" address.
  297.      * @param string $address
  298.      * @param string $name
  299.      * @return void
  300.      */
  301.   function AddAddress($address, $name = "") {
  302.     $cur = count($this->to);
  303.     $this->to[$cur][0] = trim($address);
  304.     $this->to[$cur][1] = $name;
  305.   }
  306.  
  307.   /**
  308.      * Adds a "Cc" address. Note: this function works
  309.      * with the SMTP mailer on win32, not with the "mail"
  310.      * mailer.
  311.      * @param string $address
  312.      * @param string $name
  313.      * @return void
  314.     */
  315.   function AddCC($address, $name = "") {
  316.     $cur = count($this->cc);
  317.     $this->cc[$cur][0] = trim($address);
  318.     $this->cc[$cur][1] = $name;
  319.   }
  320.  
  321.   /**
  322.      * Adds a "Bcc" address. Note: this function works
  323.      * with the SMTP mailer on win32, not with the "mail"
  324.      * mailer.
  325.      * @param string $address
  326.      * @param string $name
  327.      * @return void
  328.      */
  329.   function AddBCC($address, $name = "") {
  330.     $cur = count($this->bcc);
  331.     $this->bcc[$cur][0] = trim($address);
  332.     $this->bcc[$cur][1] = $name;
  333.   }
  334.  
  335.   /**
  336.      * Adds a "Reply-to" address.
  337.      * @param string $address
  338.      * @param string $name
  339.      * @return void
  340.      */
  341.   function AddReplyTo($address, $name = "") {
  342.     $cur = count($this->ReplyTo);
  343.     $this->ReplyTo[$cur][0] = trim($address);
  344.     $this->ReplyTo[$cur][1] = $name;
  345.   }
  346.  
  347.  
  348.   /////////////////////////////////////////////////
  349.   // MAIL SENDING METHODS
  350.   /////////////////////////////////////////////////
  351.  
  352.   /**
  353.      * Creates message and assigns Mailer. If the message is
  354.      * not sent successfully then it returns false.  Use the ErrorInfo
  355.      * variable to view description of the error.
  356.      * @return bool
  357.      */
  358.   function Send() {
  359.     $header = "";
  360.     $body = "";
  361.     $result = true;
  362.  
  363.     if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
  364.     {
  365.       $this->SetError($this->Lang("provide_address"));
  366.       return false;
  367.     }
  368.  
  369.     // Set whether the message is multipart/alternative
  370.     if(!empty($this->AltBody))
  371.     $this->ContentType = "multipart/alternative";
  372.  
  373.     $this->error_count = 0; // reset errors
  374.     $this->SetMessageType();
  375.     $header .= $this->CreateHeader();
  376.     $body = $this->CreateBody();
  377.  
  378.     if($body == "") { return false; }
  379.  
  380.     // Choose the mailer
  381.     switch($this->Mailer)
  382.     {
  383.       case "sendmail":
  384.       $result = $this->SendmailSend($header, $body);
  385.       break;
  386.       case "mail":
  387.       $result = $this->MailSend($header, $body);
  388.       break;
  389.       case "smtp":
  390.       $result = $this->SmtpSend($header, $body);
  391.       break;
  392.       default:
  393.       $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  394.       $result = false;
  395.       break;
  396.     }
  397.  
  398.     return $result;
  399.   }
  400.  
  401.   /**
  402.      * Sends mail using the $Sendmail program.
  403.      * @access private
  404.      * @return bool
  405.      */
  406.   function SendmailSend($header, $body) {
  407.     if ($this->Sender != "")
  408.     $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  409.     else
  410.     $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  411.  
  412.     if(!@$mail = popen($sendmail, "w"))
  413.     {
  414.       $this->SetError($this->Lang("execute") . $this->Sendmail);
  415.       return false;
  416.     }
  417.  
  418.     fputs($mail, $header);
  419.     fputs($mail, $body);
  420.  
  421.     $result = pclose($mail) >> 8 & 0xFF;
  422.     if($result != 0)
  423.     {
  424.       $this->SetError($this->Lang("execute") . $this->Sendmail);
  425.       return false;
  426.     }
  427.  
  428.     return true;
  429.   }
  430.  
  431.   /**
  432.      * Sends mail using the PHP mail() function.
  433.      * @access private
  434.      * @return bool
  435.      */
  436.   function MailSend($header, $body) {
  437.     $to = "";
  438.     for($i = 0; $i < count($this->to); $i++)
  439.     {
  440.       if($i != 0) { $to .= ", "; }
  441.       $to .= $this->to[$i][0];
  442.     }
  443.  
  444.     if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
  445.     {
  446.       $old_from = ini_get("sendmail_from");
  447.       ini_set("sendmail_from", $this->Sender);
  448.       $params = sprintf("-oi -f %s", $this->Sender);
  449.       $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
  450.       $header, $params);
  451.     }
  452.     else
  453.     $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  454.  
  455.     if (isset($old_from))
  456.     ini_set("sendmail_from", $old_from);
  457.  
  458.     if(!$rt)
  459.     {
  460.       $this->SetError($this->Lang("instantiate"));
  461.       return false;
  462.     }
  463.  
  464.     return true;
  465.   }
  466.  
  467.   /**
  468.      * Sends mail via SMTP using PhpSMTP (Author:
  469.      * Chris Ryan).  Returns bool.  Returns false if there is a
  470.      * bad MAIL FROM, RCPT, or DATA input.
  471.      * @access private
  472.      * @return bool
  473.      */
  474.   function SmtpSend($header, $body) {
  475.     include_once($this->PluginDir . "class.smtp.php");
  476.     $error = "";
  477.     $bad_rcpt = array();
  478.  
  479.     if(!$this->SmtpConnect())
  480.     return false;
  481.  
  482.     $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  483.     if(!$this->smtp->Mail($smtp_from))
  484.     {
  485.       $error = $this->Lang("from_failed") . $smtp_from;
  486.       $this->SetError($error);
  487.       $this->smtp->Reset();
  488.       return false;
  489.     }
  490.  
  491.     // Attempt to send attach all recipients
  492.     for($i = 0; $i < count($this->to); $i++)
  493.     {
  494.       if(!$this->smtp->Recipient($this->to[$i][0]))
  495.       $bad_rcpt[] = $this->to[$i][0];
  496.     }
  497.     for($i = 0; $i < count($this->cc); $i++)
  498.     {
  499.       if(!$this->smtp->Recipient($this->cc[$i][0]))
  500.       $bad_rcpt[] = $this->cc[$i][0];
  501.     }
  502.     for($i = 0; $i < count($this->bcc); $i++)
  503.     {
  504.       if(!$this->smtp->Recipient($this->bcc[$i][0]))
  505.       $bad_rcpt[] = $this->bcc[$i][0];
  506.     }
  507.  
  508.     if(count($bad_rcpt) > 0) // Create error message
  509.     {
  510.       for($i = 0; $i < count($bad_rcpt); $i++)
  511.       {
  512.         if($i != 0) { $error .= ", "; }
  513.         $error .= $bad_rcpt[$i];
  514.       }
  515.       $error = $this->Lang("recipients_failed") . $error;
  516.       $this->SetError($error);
  517.       $this->smtp->Reset();
  518.       return false;
  519.     }
  520.  
  521.     if(!$this->smtp->Data($header . $body))
  522.     {
  523.       $this->SetError($this->Lang("data_not_accepted"));
  524.       $this->smtp->Reset();
  525.       return false;
  526.     }
  527.     if($this->SMTPKeepAlive == true)
  528.     $this->smtp->Reset();
  529.     else
  530.     $this->SmtpClose();
  531.  
  532.     return true;
  533.   }
  534.  
  535.   /**
  536.      * Initiates a connection to an SMTP server.  Returns false if the
  537.      * operation failed.
  538.      * @access private
  539.      * @return bool
  540.      */
  541.   function SmtpConnect() {
  542.     if($this->smtp == NULL) { $this->smtp = new SMTP(); }
  543.  
  544.     //Added for Gmail support CER
  545.     $this->smtp->Protocol = $this->Protocol;
  546.  
  547.     $this->smtp->do_debug = $this->SMTPDebug;
  548.     $hosts = explode(";", $this->Host);
  549.     $index = 0;
  550.     $connection = ($this->smtp->Connected());
  551.  
  552.     // Retry while there is no connection
  553.     while($index < count($hosts) && $connection == false)
  554.     {
  555.       if(strstr($hosts[$index], ":"))
  556.       list($host, $port) = explode(":", $hosts[$index]);
  557.       else
  558.       {
  559.         $host = $hosts[$index];
  560.         $port = $this->Port;
  561.       }
  562.  
  563.       if($this->smtp->Connect($host, $port, $this->Timeout))
  564.       {
  565.         if ($this->Helo != '')
  566.         $this->smtp->Hello($this->Helo);
  567.         else
  568.         $this->smtp->Hello($this->ServerHostname());
  569.  
  570.         if($this->SMTPAuth)
  571.         {
  572.           if(!$this->smtp->Authenticate($this->Username,
  573.           $this->Password))
  574.           {
  575.             $this->SetError($this->Lang("authenticate"));
  576.             $this->smtp->Reset();
  577.             $connection = false;
  578.           }
  579.         }
  580.         $connection = true;
  581.       }
  582.       $index++;
  583.     }
  584.     if(!$connection)
  585.     $this->SetError($this->Lang("connect_host"));
  586.  
  587.     return $connection;
  588.   }
  589.  
  590.   /**
  591.      * Closes the active SMTP session if one exists.
  592.      * @return void
  593.      */
  594.   function SmtpClose() {
  595.     if($this->smtp != NULL)
  596.     {
  597.       if($this->smtp->Connected())
  598.       {
  599.         $this->smtp->Quit();
  600.         $this->smtp->Close();
  601.       }
  602.     }
  603.   }
  604.  
  605.   /**
  606.      * Sets the language for all class error messages.  Returns false
  607.      * if it cannot load the language file.  The default language type
  608.      * is English.
  609.      * @param string $lang_type Type of language (e.g. Portuguese: "br")
  610.      * @param string $lang_path Path to the language file directory
  611.      * @access public
  612.      * @return bool
  613.      */
  614.   function SetLanguage($lang_type, $lang_path = "support/") {
  615.     if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
  616.     include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  617.     else if(file_exists($lang_path.'phpmailer.lang-en.php'))
  618.     include($lang_path.'phpmailer.lang-en.php');
  619.     else
  620.     {
  621.       $this->SetError("Could not load language file");
  622.       return false;
  623.     }
  624.     $this->language = $PHPMAILER_LANG;
  625.  
  626.     return true;
  627.   }
  628.  
  629.   /////////////////////////////////////////////////
  630.   // MESSAGE CREATION METHODS
  631.   /////////////////////////////////////////////////
  632.  
  633.   /**
  634.      * Creates recipient headers.
  635.      * @access private
  636.      * @return string
  637.      */
  638.   function AddrAppend($type, $addr) {
  639.     $addr_str = $type . ": ";
  640.     $addr_str .= $this->AddrFormat($addr[0]);
  641.     if(count($addr) > 1)
  642.     {
  643.       for($i = 1; $i < count($addr); $i++)
  644.       $addr_str .= ", " . $this->AddrFormat($addr[$i]);
  645.     }
  646.     $addr_str .= $this->LE;
  647.  
  648.     return $addr_str;
  649.   }
  650.  
  651.   /**
  652.      * Formats an address correctly.
  653.      * @access private
  654.      * @return string
  655.      */
  656.   function AddrFormat($addr) {
  657.     if(empty($addr[1]))
  658.     $formatted = $addr[0];
  659.     else
  660.     {
  661.       $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
  662.       $addr[0] . ">";
  663.     }
  664.  
  665.     return $formatted;
  666.   }
  667.  
  668.   /**
  669.      * Wraps message for use with mailers that do not
  670.      * automatically perform wrapping and for quoted-printable.
  671.      * Original written by philippe.
  672.      * @access private
  673.      * @return string
  674.      */
  675.   function WrapText($message, $length, $qp_mode = false) {
  676.     $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  677.  
  678.     $message = $this->FixEOL($message);
  679.     if (substr($message, -1) == $this->LE)
  680.     $message = substr($message, 0, -1);
  681.  
  682.     $line = explode($this->LE, $message);
  683.     $message = "";
  684.     for ($i=0 ;$i < count($line); $i++)
  685.     {
  686.       $line_part = explode(" ", $line[$i]);
  687.       $buf = "";
  688.       for ($e = 0; $e<count($line_part); $e++)
  689.       {
  690.         $word = $line_part[$e];
  691.         if ($qp_mode and (strlen($word) > $length))
  692.         {
  693.           $space_left = $length - strlen($buf) - 1;
  694.           if ($e != 0)
  695.           {
  696.             if ($space_left > 20)
  697.             {
  698.               $len = $space_left;
  699.               if (substr($word, $len - 1, 1) == "=")
  700.               $len--;
  701.               elseif (substr($word, $len - 2, 1) == "=")
  702.               $len -= 2;
  703.               $part = substr($word, 0, $len);
  704.               $word = substr($word, $len);
  705.               $buf .= " " . $part;
  706.               $message .= $buf . sprintf("=%s", $this->LE);
  707.             }
  708.             else
  709.             {
  710.               $message .= $buf . $soft_break;
  711.             }
  712.             $buf = "";
  713.           }
  714.           while (strlen($word) > 0)
  715.           {
  716.             $len = $length;
  717.             if (substr($word, $len - 1, 1) == "=")
  718.             $len--;
  719.             elseif (substr($word, $len - 2, 1) == "=")
  720.             $len -= 2;
  721.             $part = substr($word, 0, $len);
  722.             $word = substr($word, $len);
  723.  
  724.             if (strlen($word) > 0)
  725.             $message .= $part . sprintf("=%s", $this->LE);
  726.             else
  727.             $buf = $part;
  728.           }
  729.         }
  730.         else
  731.         {
  732.           $buf_o = $buf;
  733.           $buf .= ($e == 0) ? $word : (" " . $word);
  734.  
  735.           if (strlen($buf) > $length and $buf_o != "")
  736.           {
  737.             $message .= $buf_o . $soft_break;
  738.             $buf = $word;
  739.           }
  740.         }
  741.       }
  742.       $message .= $buf . $this->LE;
  743.     }
  744.  
  745.     return $message;
  746.   }
  747.  
  748.   /**
  749.      * Set the body wrapping.
  750.      * @access private
  751.      * @return void
  752.      */
  753.   function SetWordWrap() {
  754.     if($this->WordWrap < 1)
  755.     return;
  756.  
  757.     switch($this->message_type)
  758.     {
  759.       case "alt":
  760.       // fall through
  761.       case "alt_attachments":
  762.       $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  763.       break;
  764.       default:
  765.       $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  766.       break;
  767.     }
  768.   }
  769.  
  770.   /**
  771.      * Assembles message header.
  772.      * @access private
  773.      * @return string
  774.      */
  775.   function CreateHeader() {
  776.     $result = "";
  777.  
  778.     // Set the boundaries
  779.     $uniq_id = md5(uniqid(time()));
  780.     $this->boundary[1] = "b1_" . $uniq_id;
  781.     $this->boundary[2] = "b2_" . $uniq_id;
  782.  
  783.     $result .= $this->HeaderLine("Date", $this->RFCDate());
  784.     if($this->Sender == "")
  785.     $result .= $this->HeaderLine("Return-Path", trim($this->From));
  786.     else
  787.     $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
  788.  
  789.     // To be created automatically by mail()
  790.     if($this->Mailer != "mail")
  791.     {
  792.       if(count($this->to) > 0)
  793.       $result .= $this->AddrAppend("To", $this->to);
  794.       else if (count($this->cc) == 0)
  795.       $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
  796.       if(count($this->cc) > 0)
  797.       $result .= $this->AddrAppend("Cc", $this->cc);
  798.     }
  799.  
  800.     $from = array();
  801.     $from[0][0] = trim($this->From);
  802.     $from[0][1] = $this->FromName;
  803.     $result .= $this->AddrAppend("From", $from);
  804.  
  805.     // sendmail and mail() extract Bcc from the header before sending
  806.     if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
  807.     $result .= $this->AddrAppend("Bcc", $this->bcc);
  808.  
  809.     if(count($this->ReplyTo) > 0)
  810.     $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
  811.  
  812.     // mail() sets the subject itself
  813.     if($this->Mailer != "mail")
  814.     $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  815.  
  816.     $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  817.     $result .= $this->HeaderLine("X-Priority", $this->Priority);
  818.     $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "] via Zen Cart");
  819.  
  820.     if($this->ConfirmReadingTo != "")
  821.     {
  822.       $result .= $this->HeaderLine("Disposition-Notification-To",
  823.       "<" . trim($this->ConfirmReadingTo) . ">");
  824.     }
  825.  
  826.     // Add custom headers
  827.     for($index = 0; $index < count($this->CustomHeader); $index++)
  828.     {
  829.       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
  830.       $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  831.     }
  832.     $result .= $this->HeaderLine("MIME-Version", "1.0");
  833.  
  834.     switch($this->message_type)
  835.     {
  836.       case "plain":
  837.       $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  838.       $result .= sprintf("Content-Type: %s; charset=\"%s\"",
  839.       $this->ContentType, $this->CharSet);
  840.       break;
  841.       case "attachments":
  842.       // fall through
  843.       case "alt_attachments":
  844.       if($this->InlineImageExists())
  845.       {
  846.         $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
  847.         "multipart/related", $this->LE, $this->LE,
  848.         $this->boundary[1], $this->LE);
  849.       }
  850.       else
  851.       {
  852.         $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
  853.         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  854.       }
  855.       break;
  856.       case "alt":
  857.       $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
  858.       $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  859.       break;
  860.     }
  861.  
  862.     if($this->Mailer != "mail")
  863.     $result .= $this->LE.$this->LE;
  864.  
  865.     return $result;
  866.   }
  867.  
  868.   /**
  869.      * Assembles the message body.  Returns an empty string on failure.
  870.      * @access private
  871.      * @return string
  872.      */
  873.   function CreateBody() {
  874.     $result = "";
  875.  
  876.     $this->SetWordWrap();
  877.  
  878.     switch($this->message_type)
  879.     {
  880.       case "alt":
  881.       $result .= $this->GetBoundary($this->boundary[1], "",
  882.       "text/plain", "");
  883.       $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  884.       $result .= $this->LE.$this->LE;
  885.       $result .= $this->GetBoundary($this->boundary[1], "",
  886.       "text/html", "");
  887.  
  888.       $result .= $this->EncodeString($this->Body, $this->Encoding);
  889.       $result .= $this->LE.$this->LE;
  890.  
  891.       $result .= $this->EndBoundary($this->boundary[1]);
  892.       break;
  893.       case "plain":
  894.       $result .= $this->EncodeString($this->Body, $this->Encoding);
  895.       break;
  896.       case "attachments":
  897.       $result .= $this->GetBoundary($this->boundary[1], "", "", "");
  898.       $result .= $this->EncodeString($this->Body, $this->Encoding);
  899.       $result .= $this->LE;
  900.  
  901.       $result .= $this->AttachAll();
  902.       break;
  903.       case "alt_attachments":
  904.       $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  905.       $result .= sprintf("Content-Type: %s;%s" .
  906.       "\tboundary=\"%s\"%s",
  907.       "multipart/alternative", $this->LE,
  908.       $this->boundary[2], $this->LE.$this->LE);
  909.  
  910.       // Create text body
  911.       $result .= $this->GetBoundary($this->boundary[2], "",
  912.       "text/plain", "") . $this->LE;
  913.  
  914.       $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  915.       $result .= $this->LE.$this->LE;
  916.  
  917.       // Create the HTML body
  918.       $result .= $this->GetBoundary($this->boundary[2], "",
  919.       "text/html", "") . $this->LE;
  920.  
  921.       $result .= $this->EncodeString($this->Body, $this->Encoding);
  922.       $result .= $this->LE.$this->LE;
  923.  
  924.       $result .= $this->EndBoundary($this->boundary[2]);
  925.  
  926.       $result .= $this->AttachAll();
  927.       break;
  928.     }
  929.     if($this->IsError())
  930.     $result = "";
  931.  
  932.     return $result;
  933.   }
  934.  
  935.   /**
  936.      * Returns the start of a message boundary.
  937.      * @access private
  938.      */
  939.   function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  940.     $result = "";
  941.     if($charSet == "") { $charSet = $this->CharSet; }
  942.     if($contentType == "") { $contentType = $this->ContentType; }
  943.     if($encoding == "") { $encoding = $this->Encoding; }
  944.  
  945.     $result .= $this->TextLine("--" . $boundary);
  946.     $result .= sprintf("Content-Type: %s; charset = \"%s\"",
  947.     $contentType, $charSet);
  948.     $result .= $this->LE;
  949.     $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  950.     $result .= $this->LE;
  951.  
  952.     return $result;
  953.   }
  954.  
  955.   /**
  956.      * Returns the end of a message boundary.
  957.      * @access private
  958.      */
  959.   function EndBoundary($boundary) {
  960.     return $this->LE . "--" . $boundary . "--" . $this->LE;
  961.   }
  962.  
  963.   /**
  964.      * Sets the message type.
  965.      * @access private
  966.      * @return void
  967.      */
  968.   function SetMessageType() {
  969.     if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
  970.     $this->message_type = "plain";
  971.     else
  972.     {
  973.       if(count($this->attachment) > 0)
  974.       $this->message_type = "attachments";
  975.       if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
  976.       $this->message_type = "alt";
  977.       if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
  978.       $this->message_type = "alt_attachments";
  979.     }
  980.   }
  981.  
  982.   /**
  983.      * Returns a formatted header line.
  984.      * @access private
  985.      * @return string
  986.      */
  987.   function HeaderLine($name, $value) {
  988.     return $name . ": " . $value . $this->LE;
  989.   }
  990.  
  991.   /**
  992.      * Returns a formatted mail line.
  993.      * @access private
  994.      * @return string
  995.      */
  996.   function TextLine($value) {
  997.     return $value . $this->LE;
  998.   }
  999.  
  1000.   /////////////////////////////////////////////////
  1001.   // ATTACHMENT METHODS
  1002.   /////////////////////////////////////////////////
  1003.  
  1004.   /**
  1005.      * Adds an attachment from a path on the filesystem.
  1006.      * Returns false if the file could not be found
  1007.      * or accessed.
  1008.      * @param string $path Path to the attachment.
  1009.      * @param string $name Overrides the attachment name.
  1010.      * @param string $encoding File encoding (see $Encoding).
  1011.      * @param string $type File extension (MIME) type.
  1012.      * @return bool
  1013.      */
  1014.   function AddAttachment($path, $name = "", $encoding = "base64",
  1015.   $type = "application/octet-stream") {
  1016.     if(!@is_file($path))
  1017.     {
  1018.       $this->SetError($this->Lang("file_access") . $path);
  1019.       return false;
  1020.     }
  1021.  
  1022.     $filename = basename($path);
  1023.     if($name == "")
  1024.     $name = $filename;
  1025.  
  1026.     $cur = count($this->attachment);
  1027.     $this->attachment[$cur][0] = $path;
  1028.     $this->attachment[$cur][1] = $filename;
  1029.     $this->attachment[$cur][2] = $name;
  1030.     $this->attachment[$cur][3] = $encoding;
  1031.     $this->attachment[$cur][4] = $type;
  1032.     $this->attachment[$cur][5] = false; // isStringAttachment
  1033.     $this->attachment[$cur][6] = "attachment";
  1034.     $this->attachment[$cur][7] = 0;
  1035.  
  1036.     return true;
  1037.   }
  1038.  
  1039.   /**
  1040.      * Attaches all fs, string, and binary attachments to the message.
  1041.      * Returns an empty string on failure.
  1042.      * @access private
  1043.      * @return string
  1044.      */
  1045.   function AttachAll() {
  1046.     // Return text of body
  1047.     $mime = array();
  1048.  
  1049.     // Add all attachments
  1050.     for($i = 0; $i < count($this->attachment); $i++)
  1051.     {
  1052.       // Check for string attachment
  1053.       $bString = $this->attachment[$i][5];
  1054.       if ($bString)
  1055.       $string = $this->attachment[$i][0];
  1056.       else
  1057.       $path = $this->attachment[$i][0];
  1058.  
  1059.       $filename    = $this->attachment[$i][1];
  1060.       $name        = $this->attachment[$i][2];
  1061.       $encoding    = $this->attachment[$i][3];
  1062.       $type        = $this->attachment[$i][4];
  1063.       $disposition = $this->attachment[$i][6];
  1064.       $cid         = $this->attachment[$i][7];
  1065.  
  1066.       $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  1067.       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  1068.       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1069.  
  1070.       if($disposition == "inline")
  1071.       $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1072.  
  1073.       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
  1074.       $disposition, $name, $this->LE.$this->LE);
  1075.  
  1076.       // Encode as string attachment
  1077.       if($bString)
  1078.       {
  1079.         $mime[] = $this->EncodeString($string, $encoding);
  1080.         if($this->IsError()) { return ""; }
  1081.         $mime[] = $this->LE.$this->LE;
  1082.       }
  1083.       else
  1084.       {
  1085.         $mime[] = $this->EncodeFile($path, $encoding);
  1086.         if($this->IsError()) { return ""; }
  1087.         $mime[] = $this->LE.$this->LE;
  1088.       }
  1089.     }
  1090.  
  1091.     $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  1092.  
  1093.     return join("", $mime);
  1094.   }
  1095.  
  1096.   /**
  1097.      * Encodes attachment in requested format.  Returns an
  1098.      * empty string on failure.
  1099.      * @access private
  1100.      * @return string
  1101.      */
  1102.   function EncodeFile ($path, $encoding = "base64") {
  1103.     if(!@$fd = fopen($path, "rb"))
  1104.     {
  1105.       $this->SetError($this->Lang("file_open") . $path);
  1106.       return "";
  1107.     }
  1108.     $magic_quotes = get_magic_quotes_runtime();
  1109.     if (version_compare(PHP_VERSION, 5.3, '<') && function_exists('set_magic_quotes_runtime')) set_magic_quotes_runtime(0);
  1110.     $file_buffer = fread($fd, filesize($path));
  1111.     $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1112.     fclose($fd);
  1113.     if (version_compare(PHP_VERSION, 5.3, '<') && function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime($magic_quotes);
  1114.     return $file_buffer;
  1115.   }
  1116.  
  1117.   /**
  1118.      * Encodes string to requested format. Returns an
  1119.      * empty string on failure.
  1120.      * @access private
  1121.      * @return string
  1122.      */
  1123.   function EncodeString ($str, $encoding = "base64") {
  1124.     $encoded = "";
  1125.     switch(strtolower($encoding)) {
  1126.       case "base64":
  1127.       // chunk_split is found in PHP >= 3.0.6
  1128.       $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1129.       break;
  1130.       case "7bit":
  1131.       case "8bit":
  1132.       $encoded = $this->FixEOL($str);
  1133.       if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1134.       $encoded .= $this->LE;
  1135.       break;
  1136.       case "binary":
  1137.       $encoded = $str;
  1138.       break;
  1139.       case "quoted-printable":
  1140.       $encoded = $this->EncodeQP($str);
  1141.       break;
  1142.       default:
  1143.       $this->SetError($this->Lang("encoding") . $encoding);
  1144.       break;
  1145.     }
  1146.     return $encoded;
  1147.   }
  1148.  
  1149.   /**
  1150.      * Encode a header string to best of Q, B, quoted or none.
  1151.      * @access private
  1152.      * @return string
  1153.      */
  1154.   function EncodeHeader ($str, $position = 'text') {
  1155.     $x = 0;
  1156.  
  1157.     switch (strtolower($position)) {
  1158.       case 'phrase':
  1159.       if (!preg_match('/[\200-\377]/', $str)) {
  1160.         // Can't use addslashes as we don't know what value has magic_quotes_sybase.
  1161.         $encoded = addcslashes($str, "\0..\37\177\\\"");
  1162.  
  1163.         if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  1164.        return ($encoded);
  1165.        else
  1166.        return ("\"$encoded\"");
  1167.      }
  1168.      $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1169.      break;
  1170.      case 'comment':
  1171.      $x = preg_match_all('/[()"]/', $str, $matches);
  1172.      // Fall-through
  1173.      case 'text':
  1174.      default:
  1175.      $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1176.      break;
  1177.    }
  1178.  
  1179.    if ($x == 0)
  1180.    return ($str);
  1181.  
  1182.    $maxlen = 75 - 7 - strlen($this->CharSet);
  1183.    // Try to select the encoding which should produce the shortest output
  1184.    if (strlen($str)/3 < $x) {
  1185.      $encoding = 'B';
  1186.      $encoded = base64_encode($str);
  1187.      $maxlen -= $maxlen % 4;
  1188.      $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1189.    } else {
  1190.      $encoding = 'Q';
  1191.      $encoded = $this->EncodeQ($str, $position);
  1192.      $encoded = $this->WrapText($encoded, $maxlen, true);
  1193.      $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
  1194.    }
  1195.  
  1196.    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1197.    $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1198.  
  1199.    return $encoded;
  1200.  }
  1201.  
  1202.  /**
  1203.     * Encode string to quoted-printable.
  1204.     * @access private
  1205.     * @return string
  1206.     */
  1207.  function EncodeQP ($str) {
  1208.    $encoded = $this->FixEOL($str);
  1209.    if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1210.    $encoded .= $this->LE;
  1211.  
  1212.    // Replace every high ascii, control and = characters
  1213.    $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
  1214.    "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1215.    // Replace every spaces and tabs when it's the last character on a line
  1216.    $encoded = preg_replace("/([\011\040])".$this->LE."/e",
  1217.    "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  1218.  
  1219.    // Maximum line length of 76 characters before CRLF (74 + space + '=')
  1220.    $encoded = $this->WrapText($encoded, 74, true);
  1221.  
  1222.    return $encoded;
  1223.  }
  1224.  
  1225.  /**
  1226.     * Encode string to q encoding.
  1227.     * @access private
  1228.     * @return string
  1229.     */
  1230.  function EncodeQ ($str, $position = "text") {
  1231.    // There should not be any EOL in the string
  1232.    $encoded = preg_replace("[\r\n]", "", $str);
  1233.  
  1234.    switch (strtolower($position)) {
  1235.      case "phrase":
  1236.      $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1237.      break;
  1238.      case "comment":
  1239.      $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1240.       case "text":
  1241.       default:
  1242.       // Replace every high ascii, control =, ? and _ characters
  1243.       $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1244.       "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1245.       break;
  1246.     }
  1247.  
  1248.     // Replace every spaces to _ (more readable than =20)
  1249.     $encoded = str_replace(" ", "_", $encoded);
  1250.  
  1251.     return $encoded;
  1252.   }
  1253.  
  1254.   /**
  1255.      * Adds a string or binary attachment (non-filesystem) to the list.
  1256.      * This method can be used to attach ascii or binary data,
  1257.      * such as a BLOB record from a database.
  1258.      * @param string $string String attachment data.
  1259.      * @param string $filename Name of the attachment.
  1260.      * @param string $encoding File encoding (see $Encoding).
  1261.      * @param string $type File extension (MIME) type.
  1262.      * @return void
  1263.      */
  1264.   function AddStringAttachment($string, $filename, $encoding = "base64",
  1265.   $type = "application/octet-stream") {
  1266.     // Append to $attachment array
  1267.     $cur = count($this->attachment);
  1268.     $this->attachment[$cur][0] = $string;
  1269.     $this->attachment[$cur][1] = $filename;
  1270.     $this->attachment[$cur][2] = $filename;
  1271.     $this->attachment[$cur][3] = $encoding;
  1272.     $this->attachment[$cur][4] = $type;
  1273.     $this->attachment[$cur][5] = true; // isString
  1274.     $this->attachment[$cur][6] = "attachment";
  1275.     $this->attachment[$cur][7] = 0;
  1276.   }
  1277.  
  1278.   /**
  1279.      * Adds an embedded attachment.  This can include images, sounds, and
  1280.      * just about any other document.  Make sure to set the $type to an
  1281.      * image type.  For JPEG images use "image/jpeg" and for GIF images
  1282.      * use "image/gif".
  1283.      * @param string $path Path to the attachment.
  1284.      * @param string $cid Content ID of the attachment.  Use this to identify
  1285.      *        the Id for accessing the image in an HTML form.
  1286.      * @param string $name Overrides the attachment name.
  1287.      * @param string $encoding File encoding (see $Encoding).
  1288.      * @param string $type File extension (MIME) type.
  1289.      * @return bool
  1290.      */
  1291.   function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  1292.   $type = "application/octet-stream") {
  1293.  
  1294.     if(!@is_file($path))
  1295.     {
  1296.       $this->SetError($this->Lang("file_access") . $path);
  1297.       return false;
  1298.     }
  1299.  
  1300.     $filename = basename($path);
  1301.     if($name == "")
  1302.     $name = $filename;
  1303.  
  1304.     // Append to $attachment array
  1305.     $cur = count($this->attachment);
  1306.     $this->attachment[$cur][0] = $path;
  1307.     $this->attachment[$cur][1] = $filename;
  1308.     $this->attachment[$cur][2] = $name;
  1309.     $this->attachment[$cur][3] = $encoding;
  1310.     $this->attachment[$cur][4] = $type;
  1311.     $this->attachment[$cur][5] = false; // isStringAttachment
  1312.     $this->attachment[$cur][6] = "inline";
  1313.     $this->attachment[$cur][7] = $cid;
  1314.  
  1315.     return true;
  1316.   }
  1317.  
  1318.   /**
  1319.      * Returns true if an inline attachment is present.
  1320.      * @access private
  1321.      * @return bool
  1322.      */
  1323.   function InlineImageExists() {
  1324.     $result = false;
  1325.     for($i = 0; $i < count($this->attachment); $i++)
  1326.     {
  1327.       if($this->attachment[$i][6] == "inline")
  1328.       {
  1329.         $result = true;
  1330.         break;
  1331.       }
  1332.     }
  1333.  
  1334.     return $result;
  1335.   }
  1336.  
  1337.   /////////////////////////////////////////////////
  1338.   // MESSAGE RESET METHODS
  1339.   /////////////////////////////////////////////////
  1340.  
  1341.   /**
  1342.      * Clears all recipients assigned in the TO array.  Returns void.
  1343.      * @return void
  1344.      */
  1345.   function ClearAddresses() {
  1346.     $this->to = array();
  1347.   }
  1348.  
  1349.   /**
  1350.      * Clears all recipients assigned in the CC array.  Returns void.
  1351.      * @return void
  1352.      */
  1353.   function ClearCCs() {
  1354.     $this->cc = array();
  1355.   }
  1356.  
  1357.   /**
  1358.      * Clears all recipients assigned in the BCC array.  Returns void.
  1359.      * @return void
  1360.      */
  1361.   function ClearBCCs() {
  1362.     $this->bcc = array();
  1363.   }
  1364.  
  1365.   /**
  1366.      * Clears all recipients assigned in the ReplyTo array.  Returns void.
  1367.      * @return void
  1368.      */
  1369.   function ClearReplyTos() {
  1370.     $this->ReplyTo = array();
  1371.   }
  1372.  
  1373.   /**
  1374.      * Clears all recipients assigned in the TO, CC and BCC
  1375.      * array.  Returns void.
  1376.      * @return void
  1377.      */
  1378.   function ClearAllRecipients() {
  1379.     $this->to = array();
  1380.     $this->cc = array();
  1381.     $this->bcc = array();
  1382.   }
  1383.  
  1384.   /**
  1385.      * Clears all previously set filesystem, string, and binary
  1386.      * attachments.  Returns void.
  1387.      * @return void
  1388.      */
  1389.   function ClearAttachments() {
  1390.     $this->attachment = array();
  1391.   }
  1392.  
  1393.   /**
  1394.      * Clears all custom headers.  Returns void.
  1395.      * @return void
  1396.      */
  1397.   function ClearCustomHeaders() {
  1398.     $this->CustomHeader = array();
  1399.   }
  1400.  
  1401.  
  1402.   /////////////////////////////////////////////////
  1403.   // MISCELLANEOUS METHODS
  1404.   /////////////////////////////////////////////////
  1405.  
  1406.   /**
  1407.      * Adds the error message to the error container.
  1408.      * Returns void.
  1409.      * @access private
  1410.      * @return void
  1411.      */
  1412.   function SetError($msg) {
  1413.     $this->error_count++;
  1414.     $this->ErrorInfo = $msg;
  1415.   }
  1416.  
  1417.   /**
  1418.      * Returns the proper RFC 822 formatted date.
  1419.      * @access private
  1420.      * @return string
  1421.      */
  1422.   function RFCDate() {
  1423.     $tz = date("Z");
  1424.     $tzs = ($tz < 0) ? "-" : "+";
  1425.     $tz = abs($tz);
  1426.     $tz = ($tz/3600)*100 + ($tz%3600)/60;
  1427.     $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  1428.  
  1429.     return $result;
  1430.   }
  1431.  
  1432.   /**
  1433.      * Returns the appropriate server variable.  Should work with both
  1434.      * PHP 4.1.0+ as well as older versions.  Returns an empty string
  1435.      * if nothing is found.
  1436.      * @access private
  1437.      * @return mixed
  1438.      */
  1439.   function ServerVar($varName) {
  1440.     global $HTTP_SERVER_VARS;
  1441.     global $HTTP_ENV_VARS;
  1442.  
  1443.     if(!isset($_SERVER))
  1444.     {
  1445.       $_SERVER = $HTTP_SERVER_VARS;
  1446.       if(!isset($_SERVER["REMOTE_ADDR"]))
  1447.       $_SERVER = $HTTP_ENV_VARS; // must be Apache
  1448.     }
  1449.  
  1450.     if(isset($_SERVER[$varName]))
  1451.     return $_SERVER[$varName];
  1452.     else
  1453.     return "";
  1454.   }
  1455.  
  1456.   /**
  1457.      * Returns the server hostname or 'localhost.localdomain' if unknown.
  1458.      * @access private
  1459.      * @return string
  1460.      */
  1461.   function ServerHostname() {
  1462.     if ($this->Hostname != "")
  1463.     $result = $this->Hostname;
  1464.     elseif ($this->ServerVar('SERVER_NAME') != "")
  1465.     $result = $this->ServerVar('SERVER_NAME');
  1466.     else
  1467.     $result = "localhost.localdomain";
  1468.  
  1469.     return $result;
  1470.   }
  1471.  
  1472.   /**
  1473.      * Returns a message in the appropriate language.
  1474.      * @access private
  1475.      * @return string
  1476.      */
  1477.   function Lang($key) {
  1478.     if(count($this->language) < 1)
  1479.     $this->SetLanguage("en"); // set the default language
  1480.  
  1481.     if(isset($this->language[$key]))
  1482.     return $this->language[$key];
  1483.     else
  1484.     return "Language string failed to load: " . $key;
  1485.   }
  1486.  
  1487.   /**
  1488.      * Returns true if an error occurred.
  1489.      * @return bool
  1490.      */
  1491.   function IsError() {
  1492.     return ($this->error_count > 0);
  1493.   }
  1494.  
  1495.   /**
  1496.      * Changes every end of line from CR or LF to CRLF.
  1497.      * @access private
  1498.      * @return string
  1499.      */
  1500.   function FixEOL($str) {
  1501.     $str = str_replace("\r\n", "\n", $str);
  1502.     $str = str_replace("\r", "\n", $str);
  1503.     $str = str_replace("\n", $this->LE, $str);
  1504.     return $str;
  1505.   }
  1506.  
  1507.   /**
  1508.      * Adds a custom header.
  1509.      * @return void
  1510.      */
  1511.   function AddCustomHeader($custom_header) {
  1512.     $this->CustomHeader[] = explode(":", $custom_header, 2);
  1513.   }
  1514. }
  1515.  
  1516.