Пример #1
0
 /**
  *
  * @param $rec_user_id
  * @param $snd_user_id
  * @param $message
  * @param $subject
  * @param $message_id
  */
 function sendingEmail($rec_user_id, $snd_user_id, $message, $subject, $message_id)
 {
     $receiver = User::find($rec_user_id);
     $to = $receiver->Email;
     // do not try to send mails to users without a mail address
     if (!$to) {
         return;
     }
     $rec_fullname = $receiver->getFullName();
     setTempLanguage($rec_user_id);
     $title = "[Stud.IP - " . $GLOBALS['UNI_NAME_CLEAN'] . "] " . kill_format(str_replace(array("\r", "\n"), '', $subject));
     if ($snd_user_id != "____%system%____") {
         $sender = User::find($snd_user_id);
         $snd_fullname = $sender->getFullName();
         $reply_to = $sender->Email;
     }
     $template = $GLOBALS['template_factory']->open('mail/text');
     $template->set_attribute('message', kill_format($message));
     $template->set_attribute('rec_fullname', $rec_fullname);
     $mailmessage = $template->render();
     $template = $GLOBALS['template_factory']->open('mail/html');
     $template->set_attribute('lang', getUserLanguagePath($rec_user_id));
     $template->set_attribute('message', $message);
     $template->set_attribute('rec_fullname', $rec_fullname);
     $mailhtml = $template->render();
     restoreLanguage();
     // Now, let us send the message
     $mail = new StudipMail();
     $mail->setSubject($title)->addRecipient($to, $rec_fullname)->setReplyToEmail('')->setBodyText($mailmessage);
     if (strlen($reply_to)) {
         $mail->setSenderEmail($reply_to)->setSenderName($snd_fullname);
     }
     $user_cfg = UserConfig::get($rec_user_id);
     if ($user_cfg->getValue('MAIL_AS_HTML')) {
         $mail->setBodyHtml($mailhtml);
     }
     if ($GLOBALS['ENABLE_EMAIL_ATTACHMENTS']) {
         foreach (get_message_attachments($message_id) as $attachment) {
             $mail->addStudipAttachment($attachment['dokument_id']);
         }
     }
     if (!get_config("MAILQUEUE_ENABLE")) {
         $mail->send();
     } else {
         MailQueueEntry::add($mail, $message_id, $rec_user_id);
     }
 }
Пример #2
0
 /**
  * Sends the collected messages from sendingMail as e-mail.
  */
 function bulkSend()
 {
     // if nothing to do, return
     if (empty($this->bulk_mail)) {
         return;
     }
     // send a mail, for each language one
     foreach ($this->bulk_mail as $lang_data) {
         foreach ($lang_data as $data) {
             $mail = new StudipMail();
             $mail->setSubject($data['title']);
             foreach ($data['users'] as $user_id => $to) {
                 $mail->addRecipient($to, get_fullname($user_id), 'Bcc');
             }
             $mail->setReplyToEmail('')->setBodyText($data['text']);
             if (strlen($data['reply_to'])) {
                 $mail->setSenderEmail($data['reply_to'])->setSenderName($snd_fullname);
             }
             $user_cfg = UserConfig::get($user_id);
             if ($user_cfg->getValue('MAIL_AS_HTML')) {
                 $mail->setBodyHtml($mailhtml);
             }
             if ($GLOBALS["ENABLE_EMAIL_ATTACHMENTS"]) {
                 foreach (get_message_attachments($data['message_id']) as $attachment) {
                     $mail->addStudipAttachment($attachment['dokument_id']);
                 }
             }
             $mail->send();
         }
     }
 }