Source for file class.phpmailer.php

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

Documentation generated on Mon, 05 May 2008 16:17:44 +0400 by phpDocumentor 1.4.0