Welcome, Guest
Username: Password: Remember me

TOPIC: E-mail sending

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

  • VentoStudio
  • VentoStudio's Avatar
  • Offline
  • New Member
  • Posts: 11
  • Thank you received: 2
  • Karma: 0
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..
Last Edit: 25 Jul 2012 13:46 by admin.
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
This is a very nice feature.
I do my best to implement it in 2.0
Coding is now a piece of cake
The administrator has disabled public write access.

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

  • VentoStudio
  • VentoStudio's Avatar
  • Offline
  • New Member
  • Posts: 11
  • Thank you received: 2
  • Karma: 0
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
Last Edit: 12 Jul 2012 08:43 by VentoStudio.
The administrator has disabled public write access.
The following user(s) said Thank You: etc, edwardcox

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

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

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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
The administrator has disabled public write access.
Time to create page: 0.095 seconds

Get Started