Hope this will help you create a module with hook_cron
function mymodule_cron() {
$time_fetch=time();
$result = db_query("SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, 'node' AS field_data_body_node_entity_type
FROM
{node} node
LEFT JOIN {node_revision} node_revision ON node.vid = node_revision.vid
LEFT JOIN {node} node_node_revision ON node_revision.nid = node_node_revision.nid
WHERE (( (node.status = '1') AND (node.type IN ('question')) AND (node.created BETWEEN $time_fetch+0 AND $time_fetch -604800) ))
ORDER BY node_created DESC")->fetchAll(PDO::FETCH_ASSOC);
//WHERE date BETWEEN DATE(NOW( ) + INTERVAL 7 DAY ))->fetchAll(PDO::FETCH_ASSOC);
$all_user = db_query("SELECT users.mail AS users_mail, users.uid AS uid, users.created AS users_created
FROM
{users} users
WHERE (( (users.status <> '0') ))
ORDER BY users_created DESC")->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $mail_data)
{
foreach ($all_user as $user_mail) {
//dpm($mail_data);
//dpm($user_mail);
//here i think you can use the drupal_mail function
//$message = drupal_mail('mymodule', 'message_key', $to, user_preferred_language($user), array('body' => $body, 'subject' => $subject, $from, TRUE));
}
}
}
the drupal mail api is here drupal_mail