1

I have a question and answer site.

I would like to send via email a list of the node title and node body of all questions created over a period e.g 24hrs or 1 week to users on my site.

I do not know which module(s) would allow me select nodes of type question and then send the list via email to users on my site.

Thank you in anticipation

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.