Send folder content as attachment using PHP

<?php
readPlaceholderContent();

/*  This function check the placeholder folder and see if there any new order placed */
function readPlaceholderContent() {
  
   $base = DIRECTORY_SEPARATOR.'home'.DIRECTORY_SEPARATOR.'devtub'.DIRECTORY_SEPARATOR.'public_html'.DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'export';
   $path = $base.DIRECTORY_SEPARATOR.'place_order'.DIRECTORY_SEPARATOR;
   $destination = $base.DIRECTORY_SEPARATOR .'archived'.DIRECTORY_SEPARATOR;
   $contents = checkFileExist( $path  );
  
   if($contents) {
   foreach ($contents as $file) {
        if(strpos($file, '.') !== (int) 0) {
            sendMailAsAttachment( $file , $path);
            copyPlaceholderFileToArchived( $file, $path , $destination );
        }
    }
   }
   
   else {
    
   }
       
   
}

/* This function check is there any new order placed */
function checkFileExist( $path  ) {
    
    if (is_dir($path)) {
       
        $contents = scandir($path);
       
        if(count($contents) > 2) {
            return $contents;
        } else {
            return false;
        }
    }
    
}

/* Copy the file from the Placeholder folder to Archived folder and remove the file from placeholder file */
function copyPlaceholderFileToArchived($file, $path , $destination) {
    if (copy($path.$file, $destination.$file)) {
        unlink($path.$file);
    }
    
}

/*  This function send the CSV order as an attachment */

function sendMailAsAttachment( $file, $path ) {
    
    $emailData = pepareEmail();
    $attachContent = pepareAttachment( $file , $path );
    $message = $emailData['message'].$attachContent;
    $ok = @mail($emailData['to'], $emailData['subject'], $message, $emailData['headers']); 
    if ($ok) { 
            echo "<p>mail sent to $to!</p>"; 
    } else { 
            echo "<p>mail could not be sent!</p>"; 
    } 
}

function pepareAttachment( $file , $path ) {
        
    $filename = $path.$file ;
    $file = fopen($filename,"rb");
    $data = fread($file,filesize($filename));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $attachContent .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$filename\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"$filename\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $attachContent .= "--{$mime_boundary}\n";

    return $attachContent;
    
}

function pepareEmail() {
    
    // email fields: to, from, subject, and so on
    $to = "order@test.com ";
    $from = "admin@admin.com"; 
    $subject ="New Orders"; 
    $message = "New Orders";
    $headers = "From: $from";

    // boundary 
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

    // headers for attachment 
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

    // multipart boundary 
    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
    $message .= "--{$mime_boundary}\n";
    
    $emailData = array (
        'to' => $to,
        'from' => $from,
        'subject' => $subject,
        'headers' => $headers,
        'message' => $message
    );
    
    return $emailData;
    
}

?>