 <?php
// emailhtml.php
// RJM Programming 
// March, 2019
// Email HTML attachment
  
//header("Access-Control-Allow-Origin: *");
//header("Access-Control-Allow-Methods: PUT, GET, POST");
//header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

$psacv="";
$okayin=true;
$subd="";

if (1 == 2) {

    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(0);
    }
}

if (strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") === false && strpos($_SERVER['HTTP_REFERER'], '/macos_say_record.php') === false) { exit; }
if (strpos($_SERVER['HTTP_REFERER'], '/macos_say_record.php') !== false && isset($_GET['sliceminusten'])) { 
  $smt="";
  if (isset($_GET['sliceminusten'])) { $smt=' (' . str_replace(" ","+",urldecode($_GET['sliceminusten'])) . ')'; } 
  $honesmt="Paste to lightgreen here (already copied from lightgreen there (but recopy and repaste yourself if last characters" . $smt . " do not match) and click yellow button to Email off this Audio player ...";
  if (strlen($smt) == 13 && strpos(str_replace("+"," ",('' . urldecode($_GET['to']))),"@") !== false && str_replace("+"," ",('' . urldecode($_GET['subj']))) != '') {
  $inlineis="<input type=hidden name=inline value=''></input>";
  if (isset($_GET['attachment']) || isset($_POST['attachment'])) {  $inlineis="";    }
  $slh="";
  if (isset($_GET['smallh'])) {   $slh=str_replace("\"","\\\"",str_replace("+"," ",urldecode($_GET['smallh']))); } 

  echo "<html><head><script type='text/javascript'> 
   var smt=('" . $smt . "').substring(2).substring(0,10), smts=''; 
   var slh=\"" . $slh . "\";  
   function onsm() {
   var wpr=null;
   var wp=window.parent;
   if (wp) { wpr=parent.document.getElementById('result'); }
  if ((window.opener && window.opener !== window) || (wp && wpr)) { 
  if (5 == 5) {   // window.opener.document.getElementById('result')) { 
  document.getElementById('divplace').innerHTML='Email sent' + smts + '.';  
  //alert(window.opener.document.getElementById('result').slice(-10) + ' vs ' + smt);  
  return true; 
  } else {   
  document.getElementById('divplace').innerHTML='Other green textbox not detected.';  
  return false;  
  }  
  } else {  
  document.getElementById('divplace').innerHTML='Not a popup window.';  
  return false; 
  }
   }
   
   
   function fixta() {
   if (document.getElementById('taready').value.indexOf('#') == -1 && ((document.getElementById('taready').value.indexOf('data:') == 0 && (document.getElementById('taready').value.indexOf('data:audio/') >= 0 || document.getElementById('taready').value.indexOf('data:video/') >= 0)) || document.getElementById('taready').value == '')) {
   if (document.getElementById('taready').value == '' || ('          ' + document.getElementById('taready').value).slice(-10) == smt) { 
   if (document.getElementById('taready').value != '') {
   if (slh != '') {
   var midbits=document.getElementById('taready').value.split('data:');
   var hbith=slh;
   for (var imi=1; imi<midbits.length; imi++) {
   slh=slh.replace('#$%', 'data:' + midbits[imi]);
   }  
   document.getElementById('taready').value='<body>' + slh + '</body>'; 
   } else {
   var midbit=document.getElementById('taready').value.split('data:')[1].split(';')[0] + ' src=' + \"'\"; 
   document.getElementById('taready').value='<body><' + midbit.substring(0,5) + ' id=thisaudio controls><source type=' + midbit + document.getElementById('taready').value.replace(/\ /g,'+') + \"'\" + '></source></' + midbit.substring(0,5) + '></body>'; 
   }
   } else {
   document.getElementById('taready').value='<body><p></p></body>'; 
   smts=' with the subject only';
   }
   return true;
   } else {
   //document.getElementById('divplace').innerHTML='Copy failed because ' + ('          ' + document.getElementById('taready').value).slice(-10) + ' paste does not match ' + smt + ' copy.';
   document.getElementById('divplace').innerHTML='Copy failed because paste does not match copy.';
   return false;
   }
   } else {
   document.getElementById('divplace').innerHTML='Incorrect data';
   return false;
   } 
   } 
   </script></head><body onload=\"document.getElementById('taready').focus(); if (wpr) {  document.getElementById('status').innerHTML='Copy and Paste Done Below ...';   } \"><h1 id=status>" . $honesmt . "</h1>
  <form target=ifplace onsubmit=\"if (fixta()) { return onsm(); } else {  return false; }\" action=./emailhtml.php method=POST>
  " . $inlineis . "
  To: <input style=width:80%; type=text name=to value='" . str_replace("+"," ",urldecode($_GET['to'])) . "'></input><br>
  Subject: <input style=width:80%; type=text name=subj value='" . str_replace("+"," ",urldecode($_GET['subj'])) . "'></input><br>
  <textarea style=width:100%;background-color:lightgreen; cols=80 rows=10 name=tdhuhta id=taready></textarea><br><br>
  <input id=sub type=submit style=background-color:yellow; value='Email'></input></form><br>
  <iframe style=display:none; name=ifplace id=ifplace src=./emailhtml.php></iframe>
  <div id=divplace></div>
  </body></html>"; 
  } else {
  echo "<html><body><p>Incorrect usage.</p></body></html>";
  }
  exit; 
} 
$phpcont="";
$body="";
$to="";
$cc="";
$bcc="";
$subj="";

$fns=[""];
$fnc=[""];

$filename="";
$hcont="";
$content="";
$ifromto=0;
$fromu=[""];
$tou=[""];

$localdt="";

$mtypes = ["audio/x-aiff","audio/wav","audio/x-wav","audio/x-pn-realaudio","audio/x-mpegurl","audio/x-aiff","audio/mpeg","audio/mid",
      "audio/basic","audio/ogg","video/x-sgi-movie","video/x-msvideo","video/quicktime","audio/mp3","video/mp4","video/mpeg",
      "video/x-la-asf","video/ogg","video/webm","audio/mp4", "image/jpeg", "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tif"];
$mexts = [".aiff",".wav",".wav",".ram",".m3u",".aiff",".mp3",".rmi",
      ".snd",".ogg",".movie",".avi",".mov",".mp3",".m4v",".mpeg",
      ".lsx",".ogv",".webm",".m4a", ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif"];

$fflist="";
$ffname="";
$subjarr=["", "", "", ""];

function this_str_replace($zxc, $zxy, $zxz) {
  global $psacv;
  if ($psacv != "") { return $psacv; }
  return str_replace($zxc, $zxy, $zxz);
}

function zmail($zris, $zxsis, $ztis, $zhis) {
     global $subjarr, $fflist, $ffname, $localdt;
     // file_put_contents("091.091","");
     if (strpos($zxsis, "[") === false && strpos($zxsis, "<") === false && $zxsis != "") {
        $zxsis.=" at [date] for [files]";
    // file_put_contents("092.092",$zxsis);
        analtoken($zxsis, "");
     }
    // file_put_contents("093.093",$fflist);
     subjtokenization($fflist, "files");
     subjtokenization($ffname, "name");
    // file_put_contents("094.094",$subjarr[0]);
     if ($ffname == "") { $zhis=str_replace("<files>", $fflist, str_replace("[files]", $fflist, $zhis)); }
     $zhis=str_replace("<files>", $fflist, str_replace("[files]", $fflist, str_replace("<name>", $ffname, str_replace("[name]", $ffname, $zhis))));
    // file_put_contents("095.095",$xsis);
     return mail($zris, subjtokenization($zxsis,"subject"), $ztis, $zhis);
}

    
function analtoken($inofinterest, $ifnotblankbody) {
  global $subjarr, $fflist, $ffname, $localdt;
  $inofinterest=trim($inofinterest);
  if ($ifnotblankbody == "" && $inofinterest != "") {   // subject
 //file_put_contents("010.010",$inofinterest);
    if (strpos($inofinterest, "[") === false && strpos($inofinterest, "<") === false && $inofinterest != "") {
        $inofinterest.=" [lf] at [date] [lf] for [files]";
    }
 //file_put_contents("011.011",$inofinterest);
    if (strpos(($inofinterest . "~"), "]~") !== false && strpos(($inofinterest . "~"), "[") !== false) {
 //file_put_contents("012.012",$inofinterest);
      $subjarr[3]="html";
      if ($localdt != "") {
      $inofinterest=str_replace("[date]", $localdt, $inofinterest);
      } else {
      $inofinterest=str_replace("[date]", date('l jS \of F Y h:i:s A'), $inofinterest);
      }
      if (isset($_SERVER['HTTP_REFERER'])) {
      $inofinterest=str_replace("[httpreferer]", str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])), $inofinterest);
      $inofinterest=str_replace("[serveraddr]", $_SERVER['SERVER_ADDR'], $inofinterest);
      $inofinterest=str_replace("[requesttime]", $_SERVER['REQUEST_TIME'], $inofinterest);
      $inofinterest=str_replace("[httpacceptlanguage]", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $inofinterest);
      $inofinterest=str_replace("[httpuseragent]", $_SERVER['HTTP_USER_AGENT'], $inofinterest);
      $inofinterest=str_replace("[remoteaddr]", $_SERVER['REMOTE_ADDR'], $inofinterest);
      $inofinterest=str_replace("[requesturi]", $_SERVER['REQUEST_URI'], $inofinterest);
      if (isset($_SERVER['PATH_INFO'])) {
      $inofinterest=str_replace("[pathinfo]", $_SERVER['PATH_INFO'], $inofinterest);
      }
      }
      if ($ffname != "") {  $inofinterest=str_replace("[name]", $ffname, $inofinterest);    }
      $inofinterest=str_replace("[lf]", "\n", $inofinterest);
      $inofinterest=str_replace("[crlf]", "\r\n", $inofinterest);
      $inofinterest=str_replace("   ", " + ", $inofinterest);
      $huharr=explode("[", $inofinterest);
// file_put_contents("013.013",$inofinterest);
      // $proposedih=$huharr[0];
      if (strpos(($inofinterest . "~"), "]") !== false && strpos(($inofinterest . "~"), "[") !== false) {
// file_put_contents("014.014",$inofinterest);
        for ($ih=1; $ih<sizeof($huharr); $ih++) {
          $thisone=explode("]", $huharr[$ih])[0];
          //if ($huharr[$ih] != ($thisone . "]")) {
          //  $proposedih.=explode(($thisone . "]"), $huharr[$ih])[1];
          //}
          if (strpos($thisone, " ") === false) {
            if (isset($_POST[$thisone])) {
              $inofinterest=str_replace("[" . $thisone . "]", str_replace("+", " ", urldecode($_POST[$thisone])), $inofinterest);
            } else if (isset($_GET[$thisone])) {
              $inofinterest=str_replace("[" . $thisone . "]", str_replace("+", " ", urldecode($_GET[$thisone])), $inofinterest);
            }
          }
        }
      }
      if (strpos(($inofinterest . "~"), "]") !== false && strpos(($inofinterest . "~"), "[") !== false) {
// file_put_contents("015.015",$inofinterest);
        $huharr=explode("[", $inofinterest);
        $proposedih=$huharr[0];
        for ($ih=1; $ih<sizeof($huharr); $ih++) {
          $thisone=explode("]", $huharr[$ih])[0];
          if ($huharr[$ih] != ($thisone . "]")) {
            $proposedih.=explode(($thisone . "]"), $huharr[$ih])[1];
          }
        }
// file_put_contents("025.025",$inofinterest);
        $subjarr[0]=str_replace("\n", " ", str_replace("\r\n", " ", $proposedih));
        if (substr($inofinterest, 0, 1) == "[") {
// file_put_contents("026.026",$inofinterest);
          $subjarr[1]=str_replace("   ", " + ",str_replace("\n", "<br>", str_replace("[", "<", str_replace("]", ">", $inofinterest))));
        } else {
        if (strpos($inofinterest, "\n") !== false) {
// file_put_contents("027.027",$inofinterest);
          $huharr=explode("\n", $inofinterest);
          $subjarr[1]="<html><body><textarea style='width:90%;font-size:28px;font-weight:bold;border:1px solid transparent;background-color:#f0f0f0;' rows=" . (1 + sizeof($huharr)) . ">" . str_replace("   ", " + ",$inofinterest) . "</textarea></body></html>";
        } else {
          $subjarr[1]="<html><body><h1>" . str_replace("   ", " + ",$inofinterest) . "</h1></body></html>";
// file_put_contents("028.028",$subjarr[1]);
        }
        }
      } else {
// file_put_contents("016.016",$inofinterest);
        $subjarr[0]=str_replace("\n", " ", str_replace("\r\n", " ", $inofinterest));
        if (strpos($inofinterest, "\n") !== false) {
          $huharr=explode("\n", $inofinterest);
          $subjarr[1]="<html><body><textarea style='width:90%;font-size:28px;font-weight:bold;border:1px solid transparent;background-color:#f0f0f0;' rows=" . (1 + sizeof($huharr)) . ">" . str_replace("   ", " + ",$inofinterest) . "</textarea></body></html>";
        } else {
          $subjarr[1]="<html><body><h1>" . str_replace("   ", " + ",$inofinterest) . "</h1></body></html>";
        }
      }
    }
  } else if ($inofinterest != "") {   // body
    if (strpos($inofinterest, "@") !== false) {
    if (strpos($inofinterest, "[") !== false && strpos($inofinterest, "]") !== false) {
    $ffname=trim(explode("[", explode(",", $inofinterest)[0])[0]);
    } else {
    $ffname=explode(",", $inofinterest)[0];
    }
    } else {
    $ifnotblankbody=trim($ifnotblankbody);
    }
  }
// file_put_contents("017.017",$inofinterest);
  return $inofinterest;
}
    
function subjtokenization($inthing, $inmode) {
  global $subjarr, $fflist, $ffname, $localdt;
  if ($inmode == "subject") {
    if ($subjarr[0] != "") {
 //file_put_contents("036.036",$subjarr[0]);
      if ($fflist == "" && $ffname == "") { return $subjarr[0];   }
      if ($fflist == "") { return str_replace("<name>", $ffname, str_replace("[name]", $ffname, $subjarr[0]));   }
      return str_replace("<name>", $ffname, str_replace("[name]", $ffname, str_replace("<files>", $fflist, str_replace("[files]", $fflist, str_replace("<file>", $fflist, str_replace("[file]", $fflist, $subjarr[0]))))));
    } else if (strpos($inthing, "[") !== false) {
      if ($fflist == "" && $ffname == "") { if ($localdt != "") {  return str_replace("[date]", $localdt, $inthing);   } else { return str_replace("[date]", date('l jS \of F Y h:i:s A'), $inthing); }  }
      if ($fflist == "") { if ($localdt != "") {  return str_replace("<name>", $ffname, str_replace("[name]", $ffname, str_replace("[date]", $localdt, $inthing))); } else { return str_replace("<name>", $ffname, str_replace("[name]", $ffname, str_replace("[date]", date('l jS \of F Y h:i:s A'), $inthing))); }  }
      if ($localdt != "") {  
      return str_replace("<name>", $ffname, str_replace("[name]", $ffname, str_replace("<files>", $fflist, str_replace("[files]", $fflist, str_replace("<file>", $fflist, str_replace("[file]", $fflist, str_replace("[date]", $localdt, $inthing)))))));
      }
      return str_replace("<name>", $ffname, str_replace("[name]", $ffname, str_replace("<files>", $fflist, str_replace("[files]", $fflist, str_replace("<file>", $fflist, str_replace("[file]", $fflist, str_replace("[date]", date('l jS \of F Y h:i:s A'), $inthing)))))));
    }
    return str_replace("<files>", $fflist, str_replace("[files]", $fflist, $inthing));
  } else if (substr($inmode,0,11) == "bodysubject") {
// file_put_contents("036.036","");
    if ($subjarr[1] != "") {
      $bsprefix="";
      
      if (strlen($inmode) > 11) {
        $bsprefix=str_replace("<body>","",str_replace("</body>","",str_replace("<html>","",str_replace("</html>","",substr($inmode,11)))));
        $tbdiv="</body>";
        $tbz=0;
        if (isset($_POST['doboth'])) {
          if (substr(($_POST['doboth'] . ' '),0,1) >= "0" && substr(($_POST['doboth'] . ' '),0,1) <= "9") {
            $tbz='' . $_POST['doboth'];
          }
        } else if (isset($_GET['doboth'])) {
          if (substr(($_GET['doboth'] . ' '),0,1) >= "0" && substr(($_GET['doboth'] . ' '),0,1) <= "9") {
            $tbz='' . $_GET['doboth'];
          }
        }
        $tbits=explode("top:", $bsprefix);
        for ($it=1; $it<sizeof($tbits); $it++) {
          $tbdiv="</div></body>";
          if ($tbz < trim(explode("px", $tbits[$it])[0])) {
            $tbz=(0 + trim(explode("px", $tbits[$it])[0]));
          }
        }
        if ($tbdiv == "</div></body>") {
          $tbz+=20;
          $bsprefix.="<div style='position:absolute;left:0px;top:" . $tbz . "px;'>";
        }
        $subjarr[1]=str_replace("</body>", $tbdiv, str_replace("<body>", "<body>" . str_replace("   ", " + ",$bsprefix), $subjarr[1]));
      }
// file_put_contents("037.037",$subjarr[1]);
      if (substr($subjarr[1], 0, 1) == "<" && strpos($subjarr[1], "</h1>") !== false) {
        $subjarr[1]=str_replace("</h1>", "</h1><h3>" . str_replace("\n", "<br>", $inthing) . "</h3>", $subjarr[1]);
      } else if (substr($subjarr[1], 0, 1) == "<" && strpos($subjarr[1], "</body>") !== false) {
        $subjarr[1]=str_replace("</body>", "<h3>" . str_replace("\n", "<br>", $inthing) . "</h3></body>", $subjarr[1]);
      }
      if ($fflist == "" || 1 == 1) { return $subjarr[1]; }
      return str_replace("   ", " + ",str_replace("<files>", $fflist, str_replace("[files]", $fflist, $subjarr[1])));
    }
  } else if ($inmode == "body") {
    if ($subjarr[2] != "") {
      return $subjarr[2];
    }
  } else if ($inmode == "contenttype") {
    if ($subjarr[3] != "") {
      return $subjarr[3];
    }
  } else if ($inmode == "file") {
// file_put_contents("057.057",$subjarr[1]);
    $subjarr[1]=str_replace("<file>", $inthing, str_replace("[file]", $inthing, $subjarr[1]));
// file_put_contents("058.058",$subjarr[1]);
  } else if ($inmode == "name" && $inthing != "") {
// file_put_contents("067.067",$subjarr[0]);
    $subjarr[0]=str_replace("<name>", $inthing, str_replace("[name]", $inthing, $subjarr[0]));
    $subjarr[1]=str_replace("<name>", $inthing, str_replace("[name]", $inthing, $subjarr[1]));
    if ($subjarr[0] != "" && $subjarr[1] != "") {
      if (strpos(preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[1]))), preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[0])))) !== false) {
        $subjarr[0].=explode("<", explode(preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[0]))), preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[1]))))[1])[0];
      }
    }
  } else if ($inmode == "files" && $inthing != "") {
// file_put_contents("067.067",$subjarr[0]);
    $subjarr[0]=str_replace("<files>", $inthing, str_replace("[files]", $inthing, $subjarr[0]));
    $subjarr[1]=str_replace("<files>", $inthing, str_replace("[files]", $inthing, $subjarr[1]));
    if ($subjarr[0] != "" && $subjarr[1] != "") {
      if (strpos(preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[1]))), preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[0])))) !== false) {
        $subjarr[0].=explode("<", explode(preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[0]))), preg_replace('/\s+/', ' ', str_replace("<br>","",str_replace("\n","",$subjarr[1]))))[1])[0];
      }
    }
  }
  return $inthing;
}
    
function ourbase64_decode($instg) {
  return $instg;
}

function fillarraysmaybe($bdin) {
  global $phpcont, $fns, $fnc, $body;
  if (substr(($bdin . "<"),0,1) == "<") {
  return $bdin;
  } else {
  $ii=0;
  if (trim($phpcont) != "") { $ii=1; }
  $bd=" " . str_replace("\n"," ",str_replace("<br>"," ",str_replace("#"," ",str_replace("&"," ",str_replace("?"," ",str_replace(","," ",$bdin)))))) . " ";
    //file_put_contents("inv.inv9", $bd);
  $htbits=explode(" http", str_replace(" HTTP", " http", $bd));
  if (sizeof($htbits) > 1) {
    for ($hi=1; $hi<sizeof($htbits); $hi++) {
     $ilen=strlen(explode(".",    explode(" ", substr($htbits[$hi],0))[0]  )[-1 + sizeof(explode(".",    explode(" ", substr($htbits[$hi],0))[0]  ))]);
     if ($ilen <= 4 && $ilen > 0 && strpos(substr($htbits[$hi],0),".") !== false && strlen(substr($htbits[$hi],0)) > 2) {
     $fcc="";
     if (strtolower(substr($htbits[$hi],0,1)) == "s") {
       try {
     $fcc=file_get_contents("http" . explode(" ", substr($htbits[$hi],1))[0]);
       } catch (Exception $ee) {
       $fcc="";
       } 
     } else {
       try {
     $fcc=file_get_contents("http" . explode(" ", substr($htbits[$hi],0))[0]);
       } catch (Exception $ee) {
       $fcc="";
       } 
     }
     if ($fcc != "") {
     $fnc[$ii]=chunk_split(base64_encode($fcc));
     $fns[$ii]=explode("#", explode("?", explode("/", explode(" ", substr($htbits[$hi],0))[0])[-1 + sizeof(explode(" ", substr($htbits[$hi],0)))])[0])[0];
     $ii++;
     }
     }
    }
  }
  $htbits=explode(" ", $bd);
  if (sizeof($htbits) > 1) {
    for ($hi=1; $hi<sizeof($htbits); $hi++) {
     $ilen=strlen(explode(".",    explode(" ", substr($htbits[$hi],0))[0]  )[-1 + sizeof(explode(".",    explode(" ", substr($htbits[$hi],0))[0]  ))]);
     if ($ilen <= 4 && $ilen > 0 && strpos(substr($htbits[$hi],0),".") !== false &&  strlen(substr($htbits[$hi],0)) > 2 && strpos(strtolower(" " . substr($htbits[$hi],0)), " http") === false) {
    //file_put_contents("inv.inv99", "" . $ilen);
       $fcc="";
       if (strpos(strtolower(" " . substr($htbits[$hi],0)), " //") !== false) {
       try {
       $fcc=file_get_contents("http:" . explode(" ", substr($htbits[$hi],0))[0]);
       } catch (Exception $ee) {
       $fcc="";
       } 
       } else if (file_exists(substr($htbits[$hi],0))) {
    //file_put_contents("inv.inv999", "" . explode(" ", substr($htbits[$hi],0))[0]);
       try {
       $fcc=file_get_contents(explode(" ", substr($htbits[$hi],0))[0]);
    //file_put_contents("inv.inv9999", "" . strlen($fcc));
       } catch (Exception $ee) {
       $fcc="";
    //file_put_contents("inv.inv99990", "" . strlen($fcc));
       } 
       }
       if ($fcc != "") {
    //file_put_contents("inv.inv999909", "" . explode("#", explode("?", explode("/", explode(" ", substr($htbits[$hi],0))[0])[-1 + sizeof(explode(" ", substr($htbits[$hi],0)))])[0])[0]);
       $fnc[$ii]=chunk_split(base64_encode($fcc));
       $fns[$ii]=explode("#", explode("?", explode("/", explode(" ", substr($htbits[$hi],0))[0])[-1 + sizeof(explode(" ", substr($htbits[$hi],0)))])[0])[0];
       $ii++;
       }
     }
    }
  }
  if ($fns[0] != "" && $phpcont == "") {  $phpcont=" "; }  
  return $bdin;
  } 
}

$subptitle='';
$subdata="";
$subfile="";
$getpostfound=false;
foreach( $_POST as  $name=>$val ) {
    //file_put_contents("inv.preinv0", "inv.inv0");
  if ($val != "") {
    //file_put_contents("jnv." . $name, "jnv.inv00 " . strlen($phpcont));
  if ($name == "tdhuhta" && $subfile != "" && $subdata != "" && strpos(str_replace("+"," ",urldecode($val)), $subfile) !== false) {
   if (!isset($_POST['subjectis']) && (strpos(str_replace("+"," ",urldecode($val)), ' srcdoc="') !== false || strpos(str_replace("+"," ",urldecode($val)), ' data="') !== false || strpos(str_replace("+"," ",urldecode($val)), ' src="') !== false)) {
      //file_put_contents('baaa.aaa','b');
      if (strpos(str_replace("+"," ",urldecode($val)), ' title="') !== false) {
      //file_put_contents('haaa.aaa',explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1]);
        if (!file_exists('../PHP/animegif/' . explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1] . 'animegif.pdf')) {
      //file_put_contents('iaaa.aaa','b');
        if (file_exists('../PHP/animegif/animegif.pdf')) {
      //file_put_contents('jaaa.aaa','b');
          copy('../PHP/animegif/animegif.pdf', '../PHP/animegif/' . explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1] . 'animegif.pdf');
      //file_put_contents('kaaa.aaa','b');
        }
        }
        if (strpos($subfile, ".pdf") !== false) {
        $psacv=explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . 'animegif.pdf';
        $subptitle='<a target=_blank href="' . explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . 'animegif.pdf">Mobile whole PDF</a><br>';
        } else if (strpos($subfile, ".gif") !== false) {
        $psacv=explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . '.gif';
        $subptitle='<a target=_blank href="' . explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . '.gif">Mobile whole Animated GIF</a><br>';
        }
        //file_put_contents('paaa.aaa',$subptitle);
      }
     $vrest=explode('"', explode(' srcdoc="',str_replace("+"," ",urldecode($val)))[1])[0];
     //$val=urlencode("<body><iframe style='width:100%;height:100vh;' srcdoc='<object style=width:100%;height:100vh; type=application/pdf data=\"" . $subdata . "\">'></iframe></body>");
     //$val=urlencode("<body><iframe style='width:100%;height:100vh;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:80vh;overflow:auto;-webkit-overflow-scrolling:touch;><object style=width:95%;height:90vh; type=application/pdf data=\"" . $subdata . "\"></div>'></iframe></body>");
     //$val=urlencode("<html><head><style> body { width:100%; height:9000px; overflow:auto; -webkit-overflow-scrolling:touch; } </style></head><body><iframe style='width:100%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;><object style=width:95%;max-height:9000px; type=application/pdf data=\"" . $subdata . "\"></div>'></iframe></body></html>");
        if (strpos($subfile, ".pdf") !== false) {
     $val=urlencode("<body>" . $subptitle . "<iframe style='width:100%;height:95vh;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:95vh;overflow:auto;-webkit-overflow-scrolling:touch;><object id=myobj style=width:95%;height:95vh; type=application/pdf data=\"" . $subdata . "\"></object></div>'></iframe></body>");
        } else if (strpos($subfile, ".gif") !== false) {
     $val=urlencode("<body>" . $subptitle . "<img src=\"" . $subdata . "\"></img></body>");
        }
   } else {
      //file_put_contents('caaa.aaa','b');
     $val=urlencode(str_replace($subfile, $subdata, str_replace("+"," ",urldecode($val))));
   }
   //file_put_contents('aaa.aaa', str_replace("+"," ",urldecode($val)));
  } else if ($name == "tdhuhta" && $subfile != "" && $subdata != "" && strpos(str_replace("+"," ",urldecode($val)), ' data="') !== false) {
   $vrest='"' . explode('"', explode(' data="',str_replace("+"," ",urldecode($val)))[1])[1];
   $val=urlencode(explode(' data="',str_replace("+"," ",urldecode($val)))[0] . ' data="' . $subdata . $vrest);
   //file_put_contents('aaaa.aaaa', str_replace("+"," ",urldecode($val)));
  }
  $getpostfound=true;
    //file_put_contents("inv.inv0", "inv.inv0");
  if ($name != "inline" && substr(($name . "      "),0,6) == "inline" && strpos(urldecode($val), ":") !== false && sizeof(explode(" ", urldecode($val))) <= 5 && trim(urldecode($val)) != "") {
    $localdt=str_replace("`", "+", str_replace("+", " ", str_replace("++", " `", urldecode($val))));
  } else if ($name == "inline") {
    if ((strpos(str_replace("+"," ",urldecode($val)), 'animegif.pdf') !== false || strpos(str_replace("+"," ",urldecode($val)), '.gif') !== false) && isset($_POST['tdhuhta'])) {
     if (file_exists(str_replace("+"," ",urldecode($val)))) {
      //file_put_contents('aaa.aaa','b');
      $subfile=str_replace("+"," ",urldecode($val));
      //$subd=file_get_contents(str_replace("+"," ",urldecode($val)));
      if (strpos(urldecode($val), '.pdf') !== false) {
      $subdata='data:application/pdf;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      } else if (strpos(urldecode($val), '.gif') !== false) {
      $subdata='data:image/gif;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      }
      $val="";
      $name="x";
      $okayin=false;
     }
    } else if (strpos(str_replace("+"," ",urldecode($val)), '.gif') !== false && isset($_POST['tdhuhta'])) {
     if (file_exists(str_replace("+"," ",urldecode($val)))) {
      //file_put_contents('aaa.aaa','b');
      $subfile=str_replace("+"," ",urldecode($val));
      //$subd=file_get_contents(str_replace("+"," ",urldecode($val)));
      $subdata='data:image/gif;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      $val="";
      $name="x";
      $okayin=false;
     }
    }
    if (strpos(("~" . strtolower(str_replace("+"," ",urldecode($val)))), "~http") !== false) {
     $fromu=explode(",", str_replace("+"," ",urldecode($val)));
     $ifromto=sizeof($fromu);
     for ($ijkh=0; $ijkh<$ifromto; $ijkh++) {
      $mediais="image/jpeg";
      $thisext=strtolower(explode('.',$fromu[$ijkh])[-1 + sizeof(explode('.',$fromu[$ijkh]))]);
      for ($iexts=0; $iexts<sizeof($mexts); $iexts++) {
          if (strtolower($thisext) == $mexts[$iexts]) {
            $mediais=$mtypes[$iexts];
          }
      }     
      $tou[$ijkh]='data:' . $mediais . ';base64,' . base64_encode(file_get_contents(str_replace("https:","http:",str_replace("HTTPS:","http:",str_replace("Https:","http:",$fromu[$ijkh])))));
     }
     $val="";
    } else if (strpos(urldecode($val), ":") !== false && sizeof(explode(" ", urldecode($val))) <= 5 && trim(urldecode($val)) != "") {
     $localdt=str_replace("`", "+", str_replace("+", " ", str_replace("++", " `", urldecode($val))));
    }
    if ($name == "inline") {
    if (strlen($val) > 100) {
    $phpcont=ourbase64_decode(urldecode($val));
    if (1 == 2) {
    $pbits=explode('"data:', $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) {  $phpcont=str_replace(explode('"',$pbits[$ii])[0],str_replace(" ","+",explode('"',$pbits[$ii])[0]),$phpcont);      }
    }
    $phpcont=str_replace(' src="//', ' src="http://', $phpcont);
    $phpcont=str_replace(" src='//", " src='http://", $phpcont);
    $phpcont=str_replace(' src=//', ' src=http://', $phpcont);
    $phpcont=str_replace(' href="//', ' href="http://', $phpcont);
    $phpcont=str_replace(" href='//", " href='http://", $phpcont);
    $phpcont=str_replace(' href=//', ' href=http://', $phpcont);
    $body="";
    }
    }
  } else if (strpos($name, "subj") !== false) {
 //file_put_contents("020.020","");
    $subj=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val)))),"");
 //file_put_contents("021.021",$subj);
  } else if (strpos(str_replace("<br>"," ",str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val)))))), "<") !== false && strpos(str_replace("<br>"," ",str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val)))))), ">") !== false) {
    //file_put_contents("inv.inv00", "inv.inv00 " . strlen($phpcont));
    if ($phpcont == "") {
    $phpcont=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    if ($fromu[0] != "") {
     for ($ijkh=0; $ijkh<$ifromto; $ijkh++) {
      $phpcont=str_replace($fromu[$ijkh], $tou[$ijkh], $phpcont);
     }
    }
    $pbits=explode('"data:', $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) {  $phpcont=str_replace(explode('"',$pbits[$ii])[0],str_replace(" ","+",explode('"',$pbits[$ii])[0]),$phpcont);      }
    $pbits=explode("'data:", $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) { if ($ii == 1) { file_put_contents("before.xxx", $phpcont);  }  $phpcont=str_replace(explode("'",$pbits[$ii])[0],str_replace(" ","+",explode("'",$pbits[$ii])[0]),$phpcont);    if ($ii == 1) { file_put_contents("after.xxx", $phpcont);  }    }
    $phpcont=str_replace(' src="//', ' src="http://', $phpcont);
    $phpcont=str_replace(" src='//", " src='http://", $phpcont);
    $phpcont=str_replace(' src=//', ' src=http://', $phpcont);
    $phpcont=str_replace(' href="//', ' href="http://', $phpcont);
    $phpcont=str_replace(" href='//", " href='http://", $phpcont);
    $phpcont=str_replace(' href=//', ' href=http://', $phpcont);
    $body="";
    }
    //file_put_contents("inv.inv00", $phpcont);
  } else if (strpos(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val))))), "@") !== false) {
     //file_put_contents("inv.inv000", "inv.inv000");
   if ($to == "") { 
    $to=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))))," ");
    } else if ($cc == "") {
    $cc=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    } else {
    $bcc=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    }
  } else if (str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',$subj)))))))))) == "") {
    $subj=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    if (str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',$subj)))))))))) == "") {
      $subj="";
    }
  } else if (substr(($phpcont . " "),0,1) != "<") {
    //file_put_contents("inv.postinv0", $body);
     //file_put_contents("inv.inv0000", "inv.inv0000");
    $body=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val)))),$subj . " ");
    //file_put_contents("inv.postinv0", $body);
    //file_put_contents("inv.inv", $body);
    fillarraysmaybe($body);
    //file_put_contents("inv.ouv", "" . sizeof($fnc) . " " . $body);
  }
  }
}
foreach( $_GET as $name=>$val ) {
    //file_put_contents("inv.invxxx00", "");
  if ($val != '') {
  if ($name == "tdhuhta" && $subfile != "" && $subdata != "" && strpos(str_replace("+"," ",urldecode($val)), $subfile) !== false) {
   if (!isset($_GET['subjectis']) && (strpos(str_replace("+"," ",urldecode($val)), ' srcdoc="') !== false || strpos(str_replace("+"," ",urldecode($val)), ' data="') !== false || strpos(str_replace("+"," ",urldecode($val)), ' src="') !== false)) {
      //file_put_contents('daaa.aaa','b');

      //file_put_contents('qbaaa.aaa','b');
      if (strpos(str_replace("+"," ",urldecode($val)), ' title="') !== false) {
      //file_put_contents('qhaaa.aaa',explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1]);
        if (!file_exists('../PHP/animegif/' . explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1] . 'animegif.pdf')) {
      //file_put_contents('qiaaa.aaa','b');
        if (file_exists('../PHP/animegif/animegif.pdf')) {
      //file_put_contents('qjaaa.aaa','b');
          copy('../PHP/animegif/animegif.pdf', '../PHP/animegif/' . explode('/animegif/', explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0])[1] . 'animegif.pdf');
      //file_put_contents('qkaaa.aaa','b');
        }
        }
        if (strpos($subfile, ".pdf") !== false) {
        $psacv=explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . 'animegif.pdf';
        $subptitle='<a target=_blank href="' . explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . 'animegif.pdf">Mobile whole PDF</a><br>';
        } else if (strpos($subfile, ".gif") !== false) {
        $psacv=explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . '.gif';
        $subptitle='<a target=_blank href="' . explode('"', explode(' title="', str_replace("+"," ",urldecode($val)))[1])[0] . '.gif">Mobile whole Animated GIF</a><br>';
        }
        //file_put_contents('qpaaa.aaa',$subptitle);
      }


     $vrest=explode('"', explode(' srcdoc="',str_replace("+"," ",urldecode($val)))[1])[0];
     //$val=urlencode("<body><iframe style='width:100%;height:100vh;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<object style=width:90%;height:90%; type=application/pdf data=\"" . $subdata . "\">'></iframe></body>");
     //$val=urlencode("<body><iframe style='width:100%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;><object style=width:95%;max-height:9000px; type=application/pdf data=\"" . $subdata . "\"></div>'></iframe></body>");
     //$val=urlencode("<html><head><style> body { width:100%; height:9000px; overflow:auto; -webkit-overflow-scrolling:touch; } </style></head><body><a target=_blank onclick=\"window.open('" . $subdata . "','_blank');\">Mobile download</a><br><iframe style='width:100%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;><object id=myobj style=width:95%;max-height:9000px; type=application/pdf data=\"" . $subdata . "\"></div>'></iframe></body></html>");
     //$val=urlencode("<body>" . $subptitle . "<iframe style='width:100%;height:95vh;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:9000px;overflow:auto;-webkit-overflow-scrolling:touch;><object id=myobj style=width:95%;max-height:9000px; type=application/pdf data=\"" . $subdata . "\"></object></div>'></iframe></body>");
        if (strpos($subfile, ".pdf") !== false) {
     $val=urlencode("<body>" . $subptitle . "<iframe style='width:100%;height:95vh;overflow:auto;-webkit-overflow-scrolling:touch;' srcdoc='<div style=width:92%;height:95vh;overflow:auto;-webkit-overflow-scrolling:touch;><object id=myobj style=width:95%;height:95vh; type=application/pdf data=\"" . $subdata . "\"></object></div>'></iframe></body>");
        } else if (strpos($subfile, ".gif") !== false) {
     $val=urlencode("<body>" . $subptitle . "<img src=\"" . $subdata . "\"></img></body>");
        }
   } else {
      //file_put_contents('faaa.aaa','b');
     $val=urlencode(str_replace($subfile, $subdata, str_replace("+"," ",urldecode($val))));
   }
  } else if ($name == "tdhuhta" && $subfile != "" && $subdata != "" && strpos(str_replace("+"," ",urldecode($val)), ' data="') !== false) {
   $vrest='"' . explode('"', explode(' data="',str_replace("+"," ",urldecode($val)))[1])[1];
   $val=urlencode(explode(' data="',str_replace("+"," ",urldecode($val)))[0] . ' data="' . $subdata . $vrest);
  }
  }
  if ($name != "inline" && substr(($name . "      "),0,6) == "inline" && strpos(urldecode($val), ":") !== false && sizeof(explode(" ", urldecode($val))) <= 5 && trim(urldecode($val)) != "") {
    $localdt=str_replace("`", "+", str_replace("+", " ", str_replace("++", " `", urldecode($val))));
  } else if ($name == "inline") {
    if ((strpos(str_replace("+"," ",urldecode($val)), 'animegif.pdf') !== false || strpos(str_replace("+"," ",urldecode($val)), '.gif') !== false) && isset($_GET['tdhuhta'])) {
     if (file_exists(str_replace("+"," ",urldecode($val)))) {
      //file_put_contents('aaaa.aaaa','b');
      $subfile=str_replace("+"," ",urldecode($val));
      //$subd=file_get_contents(str_replace("+"," ",urldecode($val)));
      if (strpos(urldecode($val), '.pdf') !== false) {
      $subdata='data:application/pdf;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      } else if (strpos(urldecode($val), '.gif') !== false) {
      $subdata='data:image/gif;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      }
      $val="";
      $name="x";
      $okayin=false;
     }
    } else if (strpos(str_replace("+"," ",urldecode($val)), '.gif') !== false && isset($_GET['tdhuhta'])) {
     if (file_exists(str_replace("+"," ",urldecode($val)))) {
      //file_put_contents('aaaa.aaaa','b');
      $subfile=str_replace("+"," ",urldecode($val));
      //$subd=file_get_contents(str_replace("+"," ",urldecode($val)));
      $subdata='data:image/gif;base64,' . base64_encode(file_get_contents(str_replace("+"," ",urldecode($val))));
      $val="";
      $name="x";
      $okayin=false;
     }
    }
    if (strpos(("~" . strtolower(str_replace("+"," ",urldecode($val)))), "~http") !== false) {
     $fromu=explode(",", str_replace("+"," ",urldecode($val)));
     $ifromto=sizeof($fromu);
     for ($ijkh=0; $ijkh<$ifromto; $ijkh++) {
      $mediais="image/jpeg";
      $thisext=strtolower(explode('.',$fromu[$ijkh])[-1 + sizeof(explode('.',$fromu[$ijkh]))]);
       for ($iexts=0; $iexts<sizeof($mexts); $iexts++) {
          if (strtolower($thisext) == $mexts[$iexts]) {
            $mediais=$mtypes[$iexts];
          }
      }     
      $tou[$ijkh]='data:' . $mediais . ';base64,' . base64_encode(file_get_contents(str_replace("https:","http:",str_replace("HTTPS:","http:",str_replace("Https:","http:",$fromu[$ijkh])))));
     }
     $val="";
    } else if (strpos(urldecode($val), ":") !== false && sizeof(explode(" ", urldecode($val))) <= 5 && trim(urldecode($val)) != "") {
     $localdt=str_replace("`", "+", str_replace("+", " ", str_replace("++", " `", urldecode($val))));
    }
    if ($name == "inline") {
    if (strlen($val) > 100) {
    $phpcont=ourbase64_decode(urldecode($val));
    if (1 == 2) {
    $pbits=explode('"data:', $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) {  
    $phpcont=str_replace(explode('"',$pbits[$ii])[0],str_replace(" ","+",explode('"',$pbits[$ii])[0]),$phpcont);      
    }
    }
    $phpcont=str_replace(' src="//', ' src="http://', $phpcont);
    $phpcont=str_replace(" src='//", " src='http://", $phpcont);
    $phpcont=str_replace(' src=//', ' src=http://', $phpcont);
    $phpcont=str_replace(' href="//', ' href="http://', $phpcont);
    $phpcont=str_replace(" href='//", " href='http://", $phpcont);
    $phpcont=str_replace(' href=//', ' href=http://', $phpcont);
    $body="";
    }
    }
  } else if ($val != "") {
    //file_put_contents("inv.invzzz00", "");
  $getpostfound=true;
  if (strpos($name, "subj") !== false) {
 //file_put_contents("030.030","");
    $subj=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val)))),"");
 //file_put_contents("031.031",$subj);
  } else if (strpos(str_replace("<br>"," ",str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val)))))), "<") !== false && strpos(str_replace("<br>"," ",str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val)))))), ">") !== false) {
    if ($phpcont == "") {
    $phpcont=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    if ($fromu[0] != "") {
     for ($ijkh=0; $ijkh<$ifromto; $ijkh++) {
      $phpcont=str_replace($fromu[$ijkh], $tou[$ijkh], $phpcont);
     }
    }
    $pbits=explode('"data:', $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) {  $phpcont=str_replace(explode('"',$pbits[$ii])[0],str_replace(" ","+",explode('"',$pbits[$ii])[0]),$phpcont);      }
    $pbits=explode("'data:", $phpcont);
    for ($ii=1; $ii<sizeof($pbits); $ii++) { if ($ii == 1) { file_put_contents("before.zzz", $phpcont);  }  $phpcont=str_replace(explode("'",$pbits[$ii])[0],str_replace(" ","+",explode("'",$pbits[$ii])[0]),$phpcont);    if ($ii == 1) { file_put_contents("after.zzz", $phpcont);  }    }
    $phpcont=str_replace(' src="//', ' src="http://', $phpcont);
    $phpcont=str_replace(" src='//", " src='http://", $phpcont);
    $phpcont=str_replace(' src=//', ' src=http://', $phpcont);
    $phpcont=str_replace(' href="//', ' href="http://', $phpcont);
    $phpcont=str_replace(" href='//", " href='http://", $phpcont);
    $phpcont=str_replace(' href=//', ' href=http://', $phpcont);
    $body="";
    }
  } else if (strpos(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",strtolower(urldecode($val))))), "@") !== false) { 
    if ($to == "") { 
    $to=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val)))), " ");
    } else if ($cc == "") {
    $cc=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    } else {
    $bcc=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    }
  } else if (str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',$subj)))))))))) == "") {
    $subj=str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val))));
    if (str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',$subj)))))))))) == "") {
      $subj="";
    }
  } else if (substr(($phpcont . " "),0,1) != "<") {
    $body=analtoken(str_replace("+"," ",str_replace("&lt;","<",str_replace("&gt;",">",urldecode($val)))),$subj . " ");
    //file_put_contents("inv.inv2", $body);
    fillarraysmaybe($body);
    //file_put_contents("inv.ouv2", "" . sizeof($fnc) . " " . $body);
  }
  } 
}


if (($phpcont . $body) != "" && $to != "") {
                $subject = $subj;
                if ($subject == "") { $subject="HTML Email Attachment"; } 
                $eol = PHP_EOL;
                $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
                if ($cc != "") { $headers .= 'CC: ' . $cc . $eol; }
                if ($bcc != "") { $headers .= 'BCC: ' . $bcc . $eol; }
                $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;

                if (trim($phpcont) != "") {
                if ($subd != "") { 
                $filename="pdfattachment.pdf";
                } else {
                $filename="htmlattachment.html";
                }
                $hcont=$phpcont; //'<html><body><div id="dcontent">' .  str_replace("+", " ", urldecode($_POST['newemailcontent'])) . '</div><style>' . explode("<style>", explode("</style>", file_get_contents(dirname(__FILE__) . "/flowchart.html"))[0])[1] . '</style></body></html>';
                $content = chunk_split(base64_encode($hcont));
                $fns[0]=$filename;
                $fnc[0]=$content;
                }
                //$uid = md5(uniqid(time()));

                // a random hash will be necessary to send mixed content
                $separator = md5(time());
                
                if ((isset($_GET['inline']) || isset($_POST['inline'])) && $okayin) { 
                if (sizeof($fns) == 1) {
                  if (trim($phpcont) != "" && $body == "") {
                   $body=$phpcont;
                   //file_put_contents('inv00x', '' . sizeof($phpcont) . ' ... ' . substr($body,0,45));
                  }
                  if (strpos(strtolower($body), '</head>') !== false) {
                   $message=explode("</head>", str_replace("</HEAD>", "</head>", str_replace("</Head>", "</head>",   $body   )))[0];
                  } else if (strpos(strtolower($fnc[0]), '</head>') !== false) {
                   $message=explode("</head>", str_replace("</HEAD>", "</head>", str_replace("</Head>", "</head>",   $fnc[0]   )))[0];
                  } else if (strpos(strtolower($body), '<body') !== false) {
                   $premessage = explode("</body>", explode("<body", str_replace("<BODY", "<body", str_replace("<Body", "<body", str_replace("</BODY>", "</body>", str_replace("</Body>", "</body>",   $body   )))))[1]   )[0] . "</body>";  
                   $pmsg=explode(">", $premessage);
                   $message="<body" . substr($premessage, strlen($pmsg[0]));
                  } else if (strpos(strtolower($fnc[0]), '<body') !== false) {
                   $premessage = explode("</body>", explode("<body", str_replace("<BODY", "<body", str_replace("<Body", "<body", str_replace("</BODY>", "</body>", str_replace("</Body>", "</body>",   $fnc[0]   )))))[1]   )[0] . "</body>";  
                   $pmsg=explode(">", $premessage);
                   $message="<body" . substr($premessage, strlen($pmsg[0]));
                  } else if (strpos(strtolower($body), '<') !== false) {
                   $message = $body;  
                  } else if (strpos(strtolower($fnc[0]), '<') !== false) {
                   $message = $fnc[0];  
                  } else if (trim($phpcont) != "") {
                   $message = '<pre>' . $fnc[0] . '</pre>';  
                  } else {
                   $message = '<pre>' . $body . '</pre>';  
                  }
                 }
               }

                if ($message == "") {
                $headers .= "MIME-Version: 1.0" . $eol;
                $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;
                $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
                $headers .= "This is a MIME encoded message." . $eol . $eol;
                

                // message
                $headers .= "--" . $separator . $eol;
                } else {
                $headers = "MIME-Version: 1.0" . $eol;
                }
 
                if ($message == "") {
                $headers .= "Content-Type: text/" . subjtokenization("plain", "contenttype") . "; charset=\"iso-8859-1\"" . $eol;
                $headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
                } else {
                if ($subd != "") {
                $headers .= "Content-Type: application/pdf" . $eol;
                } else {
                $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol;
                }
                $headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
                $headers .= subjtokenization($message, "bodysubject") . $eol . $eol; //"Please see attachments created via HTTP://www.rjmprogramming.com.au/PHP/no_body.php below:" . $eol . $eol;
                $headers .= 'To: ' . $emailto . $eol;
                $headers .= 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
                $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
                }

                $lh="";
                if (strpos(('' . $_SERVER['HTTP_REFERER']), "rjmprogramming.com.au") !== false) { 
                if (strpos($subjarr[0], ('' . $_SERVER['HTTP_REFERER'])) !== false && strpos($subjarr[0], ('' . str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])) . ' ')) == false && strpos($subjarr[0], ('' . $_SERVER['HTTP_REFERER'] . ':')) == false) { 
                 $lh=explode(' ', explode(('' . $_SERVER['HTTP_REFERER']), $subjarr[0])[1])[0];
                }
                }

                if ($phpcont != "" || sizeof($fns) > 1) {
                if ($body != "") { $body.="  "; }
                if ($message == "") {
                if (sizeof($fns) > 1) {
                if (strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") !== false) { 
                if ((isset($_POST['doboth']) || isset($_GET['doboth'])) && $subjarr[3] == "html") {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachments created via . " . this_str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])) . $lh . " below:", "bodysubject" . $hcont) . $eol . $eol;
                } else {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachments created via . " . this_str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])) . $lh . " below:", "bodysubject") . $eol . $eol;
                }
                } else {
                if ((isset($_POST['doboth']) || isset($_GET['doboth'])) && $subjarr[3] == "html") {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachments below:", "bodysubject" . $hcont) . $eol . $eol;
                } else {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachments below:", "bodysubject") . $eol . $eol;
                }
                }
                } else {
                if (strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") !== false) { 
                if ((isset($_POST['doboth']) || isset($_GET['doboth'])) && $subjarr[3] == "html") {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachment created via " . this_str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])) . $lh . " below:", "bodysubject" . $hcont) . $eol . $eol;
                } else {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachment created via " . this_str_replace("square_hr_tracing.htm?worJUNKding", "square_hr_tracing.htm#wording", ('' . $_SERVER['HTTP_REFERER'])) . $lh . " below:", "bodysubject") . $eol . $eol;
                }
                } else {
                if ((isset($_POST['doboth']) || isset($_GET['doboth'])) && $subjarr[3] == "html") {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachment below:", "bodysubject" . $hcont) . $eol . $eol;
                } else {
                $headers .= subjtokenization(str_replace("\n"," ",str_replace("<br>","\n",$body)) . "Please see attachment below:", "bodysubject") . $eol . $eol;
                }
                }
                }
                }

                if ($message == "") {
                for ($ic=0; $ic<sizeof($fns); $ic++) {
                // attachment
                $headers .= "--" . $separator . $eol;
                $headers .= "Content-Type: application/octet-stream; name=\"" . $fns[$ic] . "\"" . $eol;
                $headers .= "Content-Transfer-Encoding: base64" . $eol;
                if ($fflist == "") {
                  $fflist=$fns[$ic];
                } else {
                  $fflist.="," . $fns[$ic];
                }
                $headers .= "Content-Disposition: attachment;filename=\"" . subjtokenization($fns[$ic], "file") . "\"" . $eol;
                $headers .= $fnc[$ic] . $eol . $eol;
    //file_put_contents("inv.inv777708", "");
                }
                } else {
                $subject=str_replace("HTML Email Attachment", "Email", $subject);
    //file_put_contents("inv.inv999908", "" . str_replace("\n"," ",str_replace("<br>","\n",$body)));
                if ($subd != "") { $body=$subdata; }
                $headers .= str_replace("\n"," ",str_replace("<br>","\n",$body)) . $eol . $eol;
                }

                $headers .= "--" . $separator . "--";
                }

                if ($message != "") {  // inline HTML

 // To send HTML mail, the Content-type header must be set
 $hdrs[] = 'MIME-Version: 1.0';
 if ($subd != "") {
 $hdrs[] = 'Content-type: application/pdf';
 } else {
 $hdrs[] = 'Content-type: text/html; charset=iso-8859-1';
 }

 // Additional headers
 $hdrs[] = 'To: ' . $to;
 $hdrs[] = 'From: rmetcalfe@rjmprogramming.com.au';

 if ($cc != "") { $hdrs[] = 'CC: ' . $cc; }
 if ($bcc != "") { $hdrs[] = 'BCC: ' . $bcc; }
 $hdrs[] = 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au';

 // Mail it
 $fflist="inline HTML";
 zmail($to,  $subject, $message, implode("\r\n", $hdrs));               
                } else {
                zmail($to, $subject, "", $headers);
                }
                exit;
} 
?>
