public function NewsletterCustom::send in Newsletter 7
Same name and namespace in other branches
- 7.2 includes/newsletter.custom.inc \NewsletterCustom::send()
Replaces tokens, sends the custom newsletter and updates stats.
Return value
Array containing the sent mail status and subscribers left for next cron
File
- includes/
newsletter.custom.inc, line 67
Class
- NewsletterCustom
- Newsletter class that sends custom newsletters.
Code
public function send() {
$i = 0;
$mails_to_send = variable_get('newsletter_cron_number', 500);
$subscribers_left = array();
$status = array();
$params = array(
'template' => $this->template,
'subscriber' => '',
'format' => $this->format,
'newsletter' => $this->newsletter,
);
foreach ($this->subscribers as $subscriber) {
$language = isset($subscriber->language) ? newsletter_language_list($subscriber->language) : $this->language;
if ($i >= $mails_to_send) {
$subscribers_left[] = $subscriber;
continue;
}
$params['subscriber'] = $subscriber;
$message = drupal_mail('newsletter', 'custom', $subscriber->email, $language, $params, $this->from);
if (!$message['result']) {
newsletter_set_watchdog($this->newsletter->nnid, $this->newsletter->title, $subscriber->email, $result);
}
$status[] = $message['result'];
$i++;
}
$this
->updateNewsletter($i);
if (empty($subscribers_left) && isset($message)) {
module_invoke_all('newsletter_list_sent', $message);
}
return array(
'status' => $status,
'subscribers_left' => $subscribers_left,
);
}