Exemplo n.º 1
0
 /**
  * Sends the specified email.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionEmailSend()
 {
     $this->_assertPostOnly();
     $criteria = $this->_input->filterSingle('criteria', XenForo_Input::JSON_ARRAY);
     $criteria = $this->_filterUserSearchCriteria($criteria);
     $criteriaPrepared = $this->_prepareUserSearchCriteria($criteria);
     $email = $this->_input->filter(array('from_name' => XenForo_Input::STRING, 'from_email' => XenForo_Input::STRING, 'email_title' => XenForo_Input::STRING, 'email_format' => XenForo_Input::STRING, 'email_body' => XenForo_Input::STRING));
     $total = $this->_input->filterSingle('total', XenForo_Input::UINT);
     $transport = XenForo_Mail::getDefaultTransport();
     if ($this->_input->filterSingle('test', XenForo_Input::STRING)) {
         $this->_sendEmail(XenForo_Visitor::getInstance()->toArray(), $email, $transport);
         return $this->responseReroute(__CLASS__, 'email');
     }
     $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
     $perPage = 100;
     $users = $this->_getUserModel()->getUsers($criteriaPrepared, array('page' => $page, 'perPage' => $perPage));
     if (!$users) {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('users/email', false, array('sent' => $total)));
     } else {
         foreach ($users as $user) {
             $this->_sendEmail($user, $email, $transport);
         }
         $viewParams = array('total' => $total, 'completed' => ($page - 1) * $perPage + count($users), 'nextPage' => $page + 1, 'criteria' => $criteria, 'email' => $email);
         return $this->responseView('XenForo_ViewAdmin_User_Email_Send', 'user_email_send', $viewParams);
     }
 }
Exemplo n.º 2
0
 public function save()
 {
     $subject = $this->_options['email_subject_template']['option_value'];
     $recipient = trim($this->_options['email_recipient_email']['option_value']);
     if (strpos($recipient, ',') !== false) {
         $recipient = explode(',', $recipient);
         foreach ($recipient as &$recip) {
             $recip = trim($recip);
         }
     }
     $sender = trim($this->_options['email_sender_email']['option_value']);
     $format = $this->_options['email_format']['option_value'];
     // default to visitor's e-mail address, but stop execution for guests
     if ($sender == '') {
         if (!XenForo_Visitor::getUserId()) {
             return false;
         } else {
             $sender = XenForo_Visitor::getInstance()->email;
         }
     }
     if ($this->_options['email_message_template']['option_value'] == '') {
         $message = '';
         foreach ($this->_templateFields as $field) {
             if ($this->_options['email_hide_empty_fields']['option_value'] == array() || $this->_options['email_hide_empty_fields']['option_value'] !== array() && $field['value'] != '') {
                 $message .= $field['title'] . ': ' . $field['value'] . PHP_EOL;
             }
         }
     } else {
         $message = $this->_options['email_message_template']['option_value'];
     }
     $transport = XenForo_Mail::getDefaultTransport();
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($subject)->addTo($recipient)->setFrom(XenForo_Application::getOptions()->defaultEmailAddress)->setReplyTo($sender);
     if ($this->_attachmentHash) {
         $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
         $attachments = $attachmentModel->getAttachmentsByTempHash($this->_attachmentHash);
         foreach ($attachments as $attachmentId => $attachment) {
             $attachmentData = $attachmentModel->getAttachmentDataById($attachment['data_id']);
             $attachmentDataFile = $attachmentModel->getAttachmentDataFilePath($attachmentData);
             $fileOutput = new XenForo_FileOutput($attachmentDataFile);
             $mailAttachment = $mailObj->createAttachment($fileOutput->getContents());
             $mailAttachment->filename = $attachmentData['filename'];
             // delete the attachment as it is no longer needed
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment');
             $dw->setExistingData($attachment);
             $dw->delete();
         }
     }
     $options = XenForo_Application::get('options');
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     // create plain text message
     $bbCodeParserText = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Text'));
     $messageText = new XenForo_BbCode_TextWrapper($message, $bbCodeParserText);
     if ($format == 'html') {
         // create html message
         $bbCodeParserHtml = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
         $messageHtml = new XenForo_BbCode_TextWrapper($message, $bbCodeParserHtml);
         $mailObj->setBodyHtml(htmlspecialchars_decode($messageHtml))->setBodyText($messageText);
     } else {
         $mailObj->setBodyText($messageText);
     }
     $mailObj->send($transport);
 }