/** * Mass mailer * * @param void * @return null */ function mass_mailer() { if (!MASS_MAILER_ENABLED) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $email_data = $this->request->post('email'); $this->smarty->assign(array('email_data' => $email_data, 'exclude' => array($this->logged_user->getId()))); if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); $subject = trim(array_var($email_data, 'subject')); $body = trim(array_var($email_data, 'body')); $recipient_ids = array_var($email_data, 'recipients'); if (empty($subject)) { $errors->addError(lang('Subject is required'), 'subject'); } // if if (empty($body)) { $errors->addError(lang('Body is required'), 'body'); } // if $recipients = array(); if (is_foreachable($recipient_ids)) { $recipients = Users::findByIds(array_unique($recipient_ids)); } // if if (!is_foreachable($recipients)) { $errors->addError(lang('Please select recipients'), 'recipients'); } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if $mailer =& ApplicationMailer::mailer(); $message = new Swift_Message($subject, $body, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET); $recipients_list = new Swift_RecipientList(); foreach ($recipients as $recipient) { $name = $recipient->getDisplayName(); $email = $recipient->getEmail(); if ($name == $email) { $name = ''; } // if $recipients_list->add($email, $name); } // foreach $name = $this->logged_user->getDisplayName(); $email = $this->logged_user->getEmail(); if ($name == $email) { $name = ''; } // if if ($mailer->batchSend($message, $recipients_list, new Swift_Address($email, $name))) { flash_success('Email has been successfully sent'); } else { flash_error('Failed to send email'); } // if $this->redirectTo('admin_tools_mass_mailer'); } // if }
/** * Send error log to administrator * * @param array $errors * @return boolean */ function backup_module_log_error($errors, $send_email = false) { $log_message = is_foreachable($errors) ? implode("\n", $errors) : $errors; if ($send_email) { $mailer =& ApplicationMailer::mailer(); $recipient = new Swift_Address(); $recipient->setAddress(ADMIN_EMAIL); $recipient->setName('activeCollab admin'); $sender = new Swift_Address(); $sender->setAddress(ConfigOptions::getValue('notifications_from_email')); $sender->setName(ConfigOptions::getValue('notifications_from_name')); $tmp_message = "Automatic backup of activeCollab on " . ROOT_URL . " failed.\n\r"; $tmp_message .= "Backup returned these errors: \n\r\n\r"; $tmp_message .= $log_message; $message = new Swift_Message(); $message->setSubject('activeCollab automatic backup error log'); $message->setData($tmp_message); $message->setContentType('text/plain'); $mailer->send($message, $recipient, $sender); } // if log_message($log_message, LOG_LEVEL_ERROR, 'backup'); }