Saturday, September 15, 2012

Update K2 to send mail notifications on new comments


Really it's not a problem, is a new requirement to allow Joomla K2 component to send notifications when a new comment has been published on frontpage; i still don't understand how that functionality has not been implementd on standar release of K2.


we need to edit the code that allow to save new comments, you can find that on components/com_k2/models/item.php once.

1.- edit item.php and search for function comment()


3.- before that line add the next code:

$mainframe = &JFactory::getApplication(); $mail = &JFactory::getMailer(); $senderEmail = $mainframe->getCfg('mailfrom'); $senderName = $mainframe->getCfg('fromname'); $mail->setSender(array($senderEmail, $senderName)); $mail->setSubject(JText::_('K2_COMMENT_REPORT')); $mail->IsHTML(true); $body = " <strong>".JText::_('K2_NAME')."</strong>: ".$name." <br/> <strong>".JText::_('K2_REPORT_REASON')."</strong>: ".$reportReason." <br/> <strong>".JText::_('K2_COMMENT')."</strong>: ".nl2br($row->commentText)." <br/> "; $mail->setBody($body); $mail->ClearAddresses(); $mail->AddAddress($params->get('commentsReportRecipient', $mainframe->getCfg('mailfrom'))); $mail->Send();


  1. Hi, this is really awesome thanks a million.
    I experienced one problem when implementing it, once I click submit the comment there is an arrow that goes around and around it does not display the text your comment has been submitted and pending approval.
    Could you please assist me as to what to do to fix this?

  2. add '$response->message = ' above
    even though he says to place the new code between them - have $response->message = in both places like this:

    $response->message =
    $mainframe = &JFactory::getApplication();
    $mail = &JFactory::getMailer();
    $senderEmail = $mainframe->getCfg('mailfrom');
    $senderName = $mainframe->getCfg('fromname');
    $mail->setSender(array($senderEmail, $senderName));
    $body = "
    ".JText::_('K2_NAME').": ".$name."

    ".JText::_('K2_REPORT_REASON').": ".$reportReason."

    ".JText::_('K2_COMMENT').": ".nl2br($row->commentText)."

    $mail->AddAddress($params->get('commentsReportRecipient', $mainframe->getCfg('mailfrom')));
    $response->message =
    $response->cssClass = 'k2FormLogSuccess';
    echo json_encode($response);

  3. Read all the information that i've given in above article. It'll give u the whole idea about it.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard


  4. It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

    Selenium training in Chennai

  5. Really nice experience you have. Thank you for sharing. It will surely be an experience to someone.
    python Course in Pune
    python Course institute in Chennai
    python Training institute in Bangalore


Note: Only a member of this blog may post a comment.