Keyword

Send e-mail notification on front end item submit

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 2 months ago #151279 by Gerben
Hi,

I searched the internet to find a answer but i can't find a solution for it so maybe there are some hero's over here.
I want to add a script thats sends a notification email when a user is submitting a new item on the front end.
I found this (for comments) but i can't find the save/storing code where i can add it:

$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();

Does somebody have a good solution?

Greetings,
Geppie

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

More
8 years 2 months ago #151312 by Lefteris
Hi,

Hacking the core files is not recommended so you have to create a small plugin for that. You can start from the example K2 plugin from here github.com/joomlaworks/example-k2-plugin .

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

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

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 2 months ago #151333 by Gerben
Thanks Lefteris,
A bit of a bummer that there isn't a plugin already for it :)
I will give it a try

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

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 1 month ago - 8 years 1 month ago #151532 by Gerben
If somebody want to manage this you can use this solution:

Add on top of itemgorm.php above the rule:
syncExtraFieldsEditor();

else {
			var data = {
    name: $('#title').val(),
    namefield: $('#yourownfield').val(),
    namefield2: $('#yourownfield2'').val()
};
$.ajax({
    type: 'POST',
    url: '/email2.php',
    data: data,
    success: function(){
    }
});

And this code inside email2.php
<? define( '_JEXEC', 1 );

// this depands on where you put the email2.php
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../../' ));

require_once ( JPATH_BASE . '/includes/defines.php' );
require_once ( JPATH_BASE . '/includes/framework.php' );
$mainframeitem = JFactory::getApplication('site');
$mainframeitem->initialise();

if($_POST){
		
    $name = $_POST['name'];
    $namefield = $_POST['namefield'];
    $namefield2  = $_POST['namefield2'];
    
  
           
$text = 'Titel: '. $name .' <br> new item uploaded with detail; '. $namefield  .' and '. $namefield2  .';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: [email protected]' . "\r\n";

//send email
    mail("[email protected]", "Subject" .$name, $text, $headers);
}
?>
Last edit: 8 years 1 month ago by Krikor Boghossian. Reason: Used [code] brackets

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 1 month ago #151540 by Krikor Boghossian
Replied by Krikor Boghossian on topic Send e-mail notification on front end item submit
You forgot to to include the email2.php file. You can use Github so your code can be discovered from more people.

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

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

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 1 month ago #151567 by Gerben
Hey Krikor,

Just made a edit and put the code of the email2.php also here.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 1 month ago #151572 by Krikor Boghossian
Replied by Krikor Boghossian on topic Send e-mail notification on front end item submit
Thank you Gerben :)

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

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

  • Steven Trooster
  • Steven Trooster's Avatar
  • Offline
  • Premium Member
More
8 years 1 month ago #151673 by Steven Trooster
Replied by Steven Trooster on topic Send e-mail notification on front end item submit
There used to be a good extension by Joomkit, which allowed you to set a notification in general and per category. Unfortunately for some reason they stopped offering extensions.
www.joomkit.com

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 1 month ago #151680 by Krikor Boghossian
Replied by Krikor Boghossian on topic Send e-mail notification on front end item submit
It appears that they shifted their business model.
You can ask them if they can open source it or simply put it on Github.

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

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


Powered by Kunena Forum