Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

E-mail sending 12 Jul 2012 07:26 #2779

In my component guests can add new entries.
All new entries are not published.
Is it possible to send an email to the administrator with the notice of the new entry?
and e-mail to the user with information that his entry was received and is waiting for the publication
I found this: docs.joomla.org/Sending_email_from_extensions

function responsible for sending e-mail should probably be in my controller in the function save () and aplay (), but do not know how to do it?
E-mail messages should be sent to the address given on the form and to administrator..

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

Last edit: by admin.

Re: E-mail sending 12 Jul 2012 08:05 #2783

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
This is a very nice feature.
I do my best to implement it in 2.0
Coding is now a piece of cake

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

Re: E-mail sending 12 Jul 2012 08:39 #2784

ok, I think I managed to solve this problem:

first, in my controller (components/com_myComponent/controllers/myController.php) I add this function:
function notify ($recipient){
	# get e-mail config from Joomla
	$config =& JFactory::getConfig();
	$from = array( 
		$config->getValue( 'config.mailfrom' ),
		$config->getValue( 'config.fromname' ) 
	);
 		
	# Set some variables for the email message
	$subjectAdmin = "Admin e-mail subject";
	$subjectUser = "User e-mail subject";
	$bodyAdmin = "Admin e-mail content ...";
	$bodyUser = "User e-mail content ...";
	$toAdmin = $config->getValue( 'config.mailfrom' );
	$toUser = $recipient;

	# Invoke JMail Class
	$mailerAdmin = JFactory::getMailer();
	$mailerUser = JFactory::getMailer();
			 
	$mailerAdmin->setSender($from);
	$mailerUser->setSender($from);
		 
	$mailerAdmin->addRecipient($toAdmin);
	$mailerUser->addRecipient($toUser);
		 
	$mailerAdmin->setSubject($subjectAdmin);
	$mailerUser->setSubject($subjectUser);
		
	$mailerAdmin->setBody($bodyAdmin);
	$mailerUser->setBody($bodyUser);
			 
	# If you would like to send as HTML, include this line; otherwise, leave it out
	$mailerAdmin->isHTML();
	$mailerUser->isHTML();
			 
	# Send once you have set all of your options
	$mailerAdmin->send();
	$mailerUser->send();
}

then in function save() before this line:
$this->setRedirect(FirmyHelper::urlRequest($vars));
I add this:
$this->notify($_POST['adres_email']);
where 'adres_emial' is a field that contains the user e-mail.

Of course we can add another function parameters.
And in the body of an email send more information from the form.

I hope that everything is fine.
Maybe this will help someone.

I I use this tutorial to find out how to Joomla send e-mail:
ostraining.com/howtojoomla/how-tos/devel...our-joomla-extension
The following user(s) said Thank You: etc, edwardcox

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

Last edit: by VentoStudio.

Re: E-mail sending 15 Jul 2012 17:06 #2794

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
I used the same to send multiple emails to multiple recipients with different informations in it. Very powerful stuff indeed.

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

Re: E-mail sending 06 Sep 2015 12:00 #13435

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
The only thing I would say to VentoStudio : never use $_POST directly.
Get the value from the input object of the application.
Coding is now a piece of cake

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

  • Page:
  • 1
Time to create page: 0.064 seconds

First let me congratulate you on an excellent/outstanding product. Just tried for one hour but was very impressed.
Marret (Forum)

Get Started