示例#1
0
 function sendMailToUser($subject, $body, $user, $content, $conf, $type)
 {
     $config = JFactory::getConfig();
     $from = JOOMLA_J3 ? $config->get('mailfrom') : $config->getValue('config.mailfrom');
     $fromname = JOOMLA_J3 ? $config->get('fromname') : $config->getValue('config.fromname');
     $sitename = JOOMLA_J3 ? $config->get('sitename') : $config->getValue('config.sitename');
     $content = $this->getContent($content->id, false);
     $this->prepareMail($subject, $body, $user, $content, $conf, "user", $type);
     if ($user->email == '') {
         $mail = $content->email;
     } else {
         $mail = $user->email;
     }
     if ($mail != '') {
         if (!TMail::sendMail($from, $fromname, $mail, $subject, $body, 1)) {
             $this->setError(JText::_('ADSMANAGER_ERROR_SENDING_MAIL'));
             return false;
         }
     }
     return true;
 }
示例#2
0
 function sendmessage()
 {
     $app = JFactory::getApplication();
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $contentid = JRequest::getInt('contentid', 0);
     $this->addModelPath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_adsmanager' . DS . 'models');
     $contentmodel = $this->getModel("content");
     $content = $contentmodel->getContent($contentid);
     $configurationmodel = $this->getModel("configuration");
     $conf = $configurationmodel->getConfiguration();
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('adsmanagercontent');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('adsmanagercontent');
     try {
         $results = $dispatcher->trigger('ADSonMessageBeforeSend', array());
     } catch (Exception $e) {
         $errorMsg = $e->getMessage();
         $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=message&contentid=' . $contentid), $errorMsg, 'message');
     }
     $config = JFactory::getConfig();
     $from = JOOMLA_J3 ? $config->get('mailfrom') : $config->getValue('config.mailfrom');
     $fromname = JOOMLA_J3 ? $config->get('fromname') : $config->getValue('config.fromname');
     if (isset($content)) {
         $name = JRequest::getVar('name', "");
         $email = JRequest::getVar('email', "");
         jimport('joomla.mail.helper');
         if (!JMailHelper::isEmailAddress($email)) {
             $this->setError(JText::_('INVALID_EMAIL_ADDRESS'));
             $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), 'INVALID_EMAIL_ADDRESS', 'message');
         }
         $subject = JRequest::getVar('title', "");
         $body = JRequest::getVar('body', "");
         $body = str_replace(array("\r\n", "\n", "\r"), "<br />", $body);
         $files = array();
         for ($i = 0; $i < $conf->number_allow_attachement; $i++) {
             $file = JRequest::getVar('attach_file' . $i, null, 'FILES');
             if ($file != null && is_uploaded_file($file['tmp_name'])) {
                 $tempPath = $config->get('tmp_path');
                 move_uploaded_file($file['tmp_name'], $tempPath . '/' . basename($file['name']));
                 $files[] = $tempPath . '/' . basename($file['name']);
             }
         }
         if (empty($files)) {
             $files = null;
         }
         if ($files != null) {
             //TODO manage replyto, the problem is that replyto doesn't replace sender
             if (!TMail::sendMail($email, $name, $content->email, $subject, $body, 1, NULL, NULL, $files)) {
                 $this->setError(JText::_('ADSMANAGER_ERROR_SENDING_MAIL'));
                 $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), JText::_('ADSMANAGER_ERROR_SENDING_MAIL'), 'message');
             }
             //Uncomment if you want a copy of all email send between users
             if (isset($conf->copy_to_admin) && $conf->copy_to_admin == 1) {
                 $mailcontent = "Sender: {$name} - {$email}<br/>";
                 $mailcontent .= "Ad Owner: {$content->email} (userid={$content->userid})<br/>";
                 $mailcontent .= "Ad id: {$content->id}<br/>";
                 $mailcontent .= "Ad title: {$content->ad_headline}<br/>";
                 $mailcontent .= "Message: {$body}";
                 if (!TMail::sendMail($from, $fromname, $from, $subject, $mailcontent, 1, NULL, NULL, $filename)) {
                     $this->setError(JText::_('ADSMANAGER_ERROR_SENDING_MAIL'));
                     $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), JText::_('ADSMANAGER_ERROR_SENDING_MAIL'), 'message');
                 }
             }
             foreach ($files as $file) {
                 unlink($tempPath . '/' . basename($file['name']));
             }
         } else {
             if (!TMail::sendMail($email, $name, $content->email, $subject, $body, 1)) {
                 $this->setError(JText::_('ADSMANAGER_ERROR_SENDING_MAIL'));
                 $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), JText::_('ADSMANAGER_ERROR_SENDING_MAIL'), 'message');
             }
             $mailcontent = "Sender: {$name} - {$email}<br/>";
             $mailcontent .= "Ad Owner: {$content->email} (userid={$content->userid})<br/>";
             $mailcontent .= "Ad id: {$content->id}<br/>";
             $mailcontent .= "Ad title: {$content->ad_headline}<br/>";
             $mailcontent .= "Message: {$body}";
             //Uncomment if you want a copy of all email send between users
             if (isset($conf->copy_to_admin) && $conf->copy_to_admin == 1) {
                 if (!TMail::sendMail($from, $fromname, $from, $subject, $body, 1)) {
                     $this->setError(JText::_('ADSMANAGER_ERROR_SENDING_MAIL'));
                     $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), JText::_('ADSMANAGER_ERROR_SENDING_MAIL'), 'message');
                 }
             }
         }
     }
     $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=details&catid=' . $content->catid . '&id=' . $contentid), JText::_('ADSMANAGER_EMAIL_SENT'), 'message');
 }