<?php

    $fotoFrente = $_FILES["fotoFrente"];
    $nomefotoFrente =  $fotoFrente['name'];
    $tipofotoFrente = $fotoFrente["type"];
    $nomeTemporariofotoFrente = $fotoFrente["tmp_name"];
    $errofotoFrente = $fotoFrente["error"];
    $tamanhofotoFrente = $fotoFrente["size"];
    $extensaofotoFrente = explode(".", $nomefotoFrente);
    $extensaoActualfotoFrente = strtolower(end($extensaofotoFrente));
    $permitido = array("jpg", "jpeg", "png", "pdf");

    $fotoTras = $_FILES["fotoTras"];
    $nomefotoTras =  $fotoTras['name'];
    $tipofotoTras = $fotoTras["type"];
    $nomeTemporariofotoTras = $fotoTras["tmp_name"];
    $errofotoTras = $fotoTras["error"];
    $tamanhofotoTras = $fotoTras["size"];
    $extensaofotoTras = explode(".", $nomefotoTras);
    $extensaoActualfotoTras = strtolower(end($extensaofotoTras));
    $permitido = array("jpg", "jpeg", "png", "pdf");
    
    $matricula = $_POST["matricula"];
    $placaFrente = $_POST["placaFrente"];
    $placaTras = $_POST["placaTras"];

    if($matricula == ""){
        $matricula = null;
    }
    if($placaFrente == ""){
        $placaFrente = null;
    }
    if($placaTras == ""){
        $placaTras = null;
    }
    
    
    $message = "<h1>MATRÍCULA - ".$matricula."</h1>";
    $message .= "<h3>DADOS</h3><p>MATRÍCULA - ".$matricula."</p>
    <p>NSERIEPLACADIANTEIRA - ".$placaFrente."</p><p>NSERIEPLACATRASEIRA - ".$placaTras."</p>"; 
    
    $subject = "INFORMAÇÕES REFERENTES A MATRÍCULA - " . $matricula;
    $fromname ="MAYONGI ANGOLA";
    $fromemail = 'MAYONGI';  //if u dont have an placaTras create one on your cpanel

    $mailto = 'nilton4004@gmail.com';  //the placaTras which u want to recv this placaTras




    $content = file_get_contents($nomeTemporariofotoFrente);
    $content = chunk_split(base64_encode($content));

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

    // carriage return type (RFC)
    $eol = "\r\n";

    // main header (multipart mandatory)
    $headers = "From: ".$fromname." <".$fromemail.">" . $eol;
    $headers .= "MIME-Version: 1.0" . $eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
    $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
    $headers .= "This is a MIME encoded message." . $eol;

    // message
    $body = "--" . $separator . $eol;
    $body .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol;
    $body .= "Content-Transfer-Encoding: 8bit" . $eol;
    $body .= $message . $eol;

    // attachment
    $body .= "--" . $separator . $eol;
    $body .= "Content-Type: application/octet-stream; name=\"" . $nomefotoFrente . "\"" . $eol;
    $body .= "Content-Transfer-Encoding: base64" . $eol;
    $body .= "Content-Disposition: attachment" . $eol;
    $body .= $content . $eol;
    $body .= "--" . $separator . "--";

    //SEND Mail
    if (mail($mailto, $subject, $body, $headers)) {
        echo "mail send ... OK"; // do what you want after sending the placaTras
        
        
    } else {
        echo "mail send ... ERROR!";
        print_r( error_get_last() );
    }

    