Programmatically send newsletter in hook_cron

Last updated on
11 March 2021

This documentation needs work. See "Help improve this page" in the sidebar.

This sets the sent status of the newsletter to pending. The newsletter will be sent during the next cron runs.

function yourmodulename_cron() {
  $nid = 1;
  $node = node_load($nid);
  if (yourcondition) {
    db_query("UPDATE {simplenews_newsletters}
                     SET s_status = '1'  
                     WHERE nid = %d", $node->nid);
    /* Uncomment the line below if using Simplenews 6.x-2.x */
    /* module_load_include('inc', 'simplenews', 'includes/simplenews.mail'); */
    simplenews_send_node($node);
  }
} 

Help improve this page

Page status: Needs work

You can: