<?php
// emoji_overlay_emailer.php
// RJM Programming
// November, 2016
// Be the emailing helper for emoji_overlay.htm

if (isset($_GET['htmlis']) && isset($_GET['to'])) {
      $emailto = urldecode($_GET['to']);

      $eol = PHP_EOL;
      $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
      $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
      
      $filename="rjmprogramming-emoji-overlay.html";
      $subject = "Your Emoji Overlay courtesy of RJM Programming http://www.rjmprogramming.com.au/HTMLCSS/emoji_overlay.htm";
      $cont='<!doctype html><html><head><meta charset="UTF-8"><title>Your Emoji Overlay courtesy of RJM Programming http://www.rjmprogramming.com.au/HTMLCSS/emoji_overlay.htm</title></head><body>' . urldecode($_GET['htmlis']) . '</body></html>';
      $content = chunk_split(base64_encode($cont));
      //$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-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($emailto, $subject, "", $headers);
}
?>