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
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;
}