Keyword

Admin Email on new comment

  • Nico Eshuis
  • Nico Eshuis's Avatar Topic Author
  • Offline
  • New Member
More
12 years 1 month ago - 12 years 1 month ago #102929 by Nico Eshuis
Admin Email on new comment was created by Nico Eshuis
Dear All,

I'm trying to send an email to the admin user (as configured in the config of Joomla). I want to do this using php. The k2 comments on the front-end are saved using Ajax. But when I add (hack) a mailing function to the save()-function of administrator/components/com_k2/models/comments.php nothing happens.

According to the saveComment()-function of the front-end controller (components/com_k2/controllers/comments.php) the above model is used for saving the comment but the mail doesn't get send. Is this a Ajax related issue maybe?

Can anyone point me in the right direction?

administrator/components/com_k2/models/comments.php
function save() {

                $mainframe = &JFactory::getApplication();
                $user = &JFactory::getUser();
                $db = &JFactory::getDBO();
                $id = JRequest::getInt('commentID');
                $item = &JTable::getInstance('K2Item', 'Table');
                $row = &JTable::getInstance('K2Comment', 'Table');
                $row->load($id);
                if($mainframe->isSite()){
                        $item->load($row->itemID);
                        if ($item->created_by != $user->id) {
                                JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                        }
                }
                $row->commentText = JRequest::getVar('commentText', '', 'default', 'string', 4);
                $row->store();
                $error = null;
                if(!$this->sendMail())
                {
                        $error = "Mail couldn't be send";
                }
                $cache = &JFactory::getCache('com_k2');
                $cache->clean();
                $response = new JObject;
                $response->comment = $row->commentText;
                $response->message = JText::_('K2_COMMENT_SAVED');
                unset($response->_errors);
                require_once (JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'JSON.php');
                $json = new Services_JSON;
                if($error)
                {
                        $reponse->message = $error;
                        
                }
                echo $json->encode($response);
                $mainframe->close();
        }
        function sendMail()
        {
                $config = &JFactory::getConfig();
                $user['fromname'] = $config->get('fromname');
                $user['mailfrom'] = $config->get('mailfrom');
                $adminmail = "[email protected]";
                $emailSubject = "Er is een reactie geplaatst op de website";
                $emailBody = "Er is een reactie geplaatst op de website bij ".JFactory::getURI()." \n Bekijk de lijst met reacties onder K2 > Reacties in het administratiegedeelte van de website.";
                $return = &JFactory::getMailer()->sendMail($user['mailfrom'], $user['fromname'], $adminmail, $emailSubject, $emailBody, 0, "[email protected]");
                return $return;
        }

Please Log in or Create an account to join the conversation.

More
12 years 4 weeks ago #102930 by Lefteris
Replied by Lefteris on topic Re: Admin Email on new comment
Hi. You should debug your code to see where it fails. Also try to put your code on the front-end item model ( /components/com_k2/models/item.php) in the comment function.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Nico Eshuis
  • Nico Eshuis's Avatar Topic Author
  • Offline
  • New Member
More
12 years 4 weeks ago - 12 years 4 weeks ago #102931 by Nico Eshuis
Replied by Nico Eshuis on topic Re: Admin Email on new comment
Thanks for your reply. The problem is that it works for other components. It has nothing to do with the function being called by Ajax?

Please Log in or Create an account to join the conversation.

More
12 years 4 weeks ago #102932 by Lefteris
Replied by Lefteris on topic Re: Admin Email on new comment
It has nothing to do that it's Ajax. It's still a request that will execute this function.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Nico Eshuis
  • Nico Eshuis's Avatar Topic Author
  • Offline
  • New Member
More
12 years 3 weeks ago #102933 by Nico Eshuis
Replied by Nico Eshuis on topic Re: Admin Email on new comment
Okay thanks, will look into this further.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum