<?php

function getArrayFromDBTable($DBTableRes) {
    $tmpArr = array();

    if(mysqli_num_rows($DBTableRes) > 0){
        while( $row = mysqli_fetch_assoc($DBTableRes) ){
            $tmpArr[] = $row;
        }
    }

    return $tmpArr;

}

$to = 'zascia@ukr.net';
$message = 'This is the test message.';
$subject = 'Cron test';
$headers = 'From: zascia@ukr.net' . "rn" .
           'Reply-To: zascia@ukr.net';
//@mail($to, $subject, $message, $headers);

$usersListSql = "SELECT `statusDate`, `userGuid` FROM `reminders` WHERE DATE(statusDate) = DATE_SUB(CURDATE(), INTERVAL 5 DAY)";


//DB Test server section
$dbHost = 'localhost';
$dbUsername = 'h4053_smartUser1';
$dbPassword = 'Denmark92';
$dbName = 'h4053_smartresponsesites';

//Create connection and select DB
$conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);

if (mysqli_connect_errno()) {
    die("Unable to connect database: " . mysqli_connect_errno());
}

if (!mysqli_set_charset($conn, "utf8")) {
    printf("Encoding error utf8: %s\n", mysqli_error($conn));
    exit();
}

$to = 'zascia@ukr.net';
$subject = 'Reminder test';
$message = "";
$headers = 'From: zascia@ukr.net' . "rn" .
           'Reply-To: zascia@ukr.net';

$result = mysqli_query($conn, $usersListSql);
$resultArray = getArrayFromDBTable($result);

if (empty($resultArray)) {
    $message = "No rows affected by the query";
} else {
    // main logic for newrows is here
    foreach ($resultArray as $key => $resultArrayRow) {
        $message .= $key . ": " . $resultArrayRow['userGuid'] . "; ";
    }

}

mysqli_close($conn);

@mail($to, $subject, $message, $headers);

?>