Guest User

Untitled

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