<?php
require_once __DIR__ . '/send_daily_report.php';

$result = sendDailyReportMail(date('Y-m-d'));

$logLine = '[' . date('Y-m-d H:i:s') . '] ' . $result['message'];

if (!empty($result['recipients'])) {
    $logLine .= ' | Recipients: ' . implode(', ', $result['recipients']);
}

if (!empty($result['file'])) {
    $logLine .= ' | File: ' . $result['file'];
}

$logLine .= PHP_EOL;

file_put_contents(__DIR__ . '/daily_report_mail.log', $logLine, FILE_APPEND);

if (php_sapi_name() === 'cli') {
    echo $logLine;
}
?>