<?php
// scientific_research.php
// Help out scientific_research.htm with large data set emails
// RJM Programming
// April, 2017



if (isset($_POST['srclues'])) {
  if (1 == 1) {
            $hcont=@file_get_contents("scientific_research.htm");
            $hcont=str_replace('var mores = ','var mores = "' . urldecode($_POST['srclues']) . '"; /' . '/ ', $hcont);
if (isset($_POST['prevscore'])) {
            $hcont=str_replace('var prevscore = ','var prevscore = "' . urldecode($_POST['prevscore']) . '"; /' . '/ ', $hcont);
}
if (isset($_POST['prevlist'])) {
            $hcont=str_replace('var prevlist = ','var prevlist = "' . urldecode($_POST['prevlist']) . '"; /' . '/ ', $hcont);
}
if (isset($_POST['emailee'])) {
            $hcont=str_replace('fill.in@email.to',urldecode($_POST['emailee']), $hcont);
}
            //echo $hcont;
            $subject = urldecode($_POST['subject']);
            $to = urldecode($_POST['emailee']);
            $eol = PHP_EOL;
            $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
            $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
      
            $filename="scientific_research.htm"; 
    		$content = chunk_split(base64_encode($hcont));
    		//$uid = md5(uniqid(time()));

    		// a random hash will be necessary to send mixed content
    		$separator = md5(time());

    		$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;
    		$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
    		$headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;

    		$headers .= "Please see attachment below:" . $eol . $eol;
    		
            //ourpremail($tem, $mysubject, "", $headers . "--" . $separator . "--");

    		// attachment
    		$headers .= "--" . $separator . $eol;
    		$headers .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
    		$headers .= "Content-Transfer-Encoding: base64" . $eol;
    		$headers .= "Content-Disposition: attachment;filename=\"" . $filename . "\"" . $eol;
    		$headers .= $content . $eol . $eol;
    		
    		$headers .= "--" . $separator . "--";
    		
            mail($to, $subject, "", $headers);  
            echo "<html><body onload=' alert(\"Email sent.\"); '></body></html>";
  } else {
            echo "<html><body></body></html>";
  }
} else if (isset($_GET['c'])) {
  echo "";
} else {
  $hcont=@file_get_contents("scientific_research.htm");
  echo $hcont;
}

?>
