function simplenews_node_tab_send_form_submit in Simplenews 7
Same name and namespace in other branches
- 6.2 simplenews.module \simplenews_node_tab_send_form_submit()
- 7.2 includes/simplenews.admin.inc \simplenews_node_tab_send_form_submit()
@todo
File
- includes/
simplenews.admin.inc, line 1981 - Newsletter admin, subscription admin, simplenews settings
Code
function simplenews_node_tab_send_form_submit($form, &$form_state) {
$values = $form_state['values'];
$node = node_load($values['nid']);
// Send newsletter to all subscribers or send test newsletter
module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_NOW) {
simplenews_add_node_to_spool($node);
// Attempt to send immediatly, if configured to do so.
if (simplenews_mail_attempt_immediate_send(array(
'nid' => $node->nid,
))) {
drupal_set_message(t('Newsletter %title sent.', array(
'%title' => $node->title,
)));
}
else {
drupal_set_message(t('Newsletter %title pending.', array(
'%title' => $node->title,
)));
}
}
elseif ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_TEST) {
simplenews_send_test($node, $form_state['test_addresses']);
}
// If the selected command is send on publish, just set the newsletter status.
if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_PUBLISH) {
$newsletter = simplenews_newsletter_load($node->nid);
if (!$newsletter) {
$newsletter = simplenews_newsletter_defaults($node);
}
$newsletter->status = SIMPLENEWS_STATUS_SEND_PUBLISH;
simplenews_newsletter_save($newsletter);
drupal_set_message(t('The newsletter will be sent when the content is published.'));
}
}