<?php
// camera_api.php
// Email helper for camera_api.htm
// RJM Programming
// November, 2016

if (isset($_POST['mode']) && strpos($_SERVER['SERVER_NAME'], "rjmprogramming.com.au") !== false) {
  if ($_POST['mode'] != '' && isset($_POST['mydurl'])) {

    if (isset($_POST['mymobile'])) {
     if ($_POST['mymobile'] != "") {
      $mtm = urldecode($_POST['mymobile']);
      $tos = explode("?", $mtm);
      $to = str_replace("mailto:", "", $tos[0]);
      $subjects = explode("&", $tos[1]);
      $subject = str_replace("subject=", "", $subjects[0]);
      $body = ($_POST['mydurl']);
      $eol = PHP_EOL;
      $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
      $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
      
      $fname = explode(";", $body);
      $filename=str_replace("quicktime", "mp4", str_replace("/", ".", str_replace("data:", "", $fname[0]))); 
      $filename="media.html";
    		$content = chunk_split(base64_encode($body));
    		//$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);
     }
    }
   
  }
} 

?>
