<?php

function sendMail($sender, $time, $email, $ipAddress) {
    $to = $email;
    $from = $sender."@".$sender."-demo.cdu.gov.hr";
    $subject = "CDU Webs - Test ".$sender;
    $time = str_replace(' ', '', $time);


    $boundary = md5(time());
    $headers = "From: " . $from . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=" . $boundary . "\r\n";
    $path = 'images/' . $sender . "_" . $time . '.jpg'; 
    $fileContent = file_get_contents($path);
    $attachment = chunk_split(base64_encode($fileContent));

    $message = "--" . $boundary . "\r\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 7bit\r\n";
    $message .= "\r\n";
    $message .= "Link na sliku: https://$sender-demo.cdu.gov.hr/cpanel-test-cdu/images/$sender";
    $message .= "_$time.jpg\r\n";
    $message .= "\r\n";
    $message .= "IP adresa: $ipAddress";
    $message .= "\r\n";
    $message .= "--" . $boundary . "\r\n";
    $message .= "Content-Type: image/jpeg\r\n";
    $message .= "Content-Disposition: attachment; filename=\"$sender"."_"."$time\"\r\n";
    $message .= "Content-Transfer-Encoding: base64\r\n";
    $message .= "\r\n";
    $message .= $attachment . "\r\n";
    $message .= "--" . $boundary . "--";

    $result = mail($to, $subject, $message, $headers, "-f '$from'");

    return $result;
}


?>