Page 1 of 1

Adding an autoresponder to a registration form

Posted: Sun Sep 06, 2009 4:22 pm
by Star6966
Hi

I am trying to add an auto-responder to a registration form so that when the user registers, the program will send a form message to their e-mail

Can anyone tell me how to go about doing this?

Thanks

Star6966

Re: Adding an autoresponder to a registration form

Posted: Sun Sep 06, 2009 7:05 pm
by ooffick
Hi,

which version of Joomla do you have?

Olaf

Re: Adding an autoresponder to a registration form

Posted: Mon Sep 07, 2009 4:55 pm
by Star6966
1.0

Re: Adding an autoresponder to a registration form

Posted: Mon Sep 07, 2009 9:09 pm
by ooffick
Please migrate to Joomla 1.5:
http://docs.joomla.org/Upgrading_1.5_fr ... 5x_version

Please note the Joomla 1.0 End-of-Life notice:
http://community.joomla.org/blogs/commu ... f-age.html

Olaf

Re: Adding an autoresponder to a registration form

Posted: Tue Sep 08, 2009 12:07 am
by Star6966
ok
how would I do it in 1.5?

Re: Adding an autoresponder to a registration form

Posted: Tue Sep 08, 2009 9:28 am
by ooffick
In Joomla 1.5 you would create a small plugin which listens on an Event like onAfterStoreUser:

http://docs.joomla.org/Reference:User_E ... rStoreUser

Olaf

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 1:09 am
by Star6966
Ok

and how would I get it to send a message

I am pretty new at this kind of programing

Thanks alot

Star6966

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 1:39 am
by Star6966
would this work in 1.5?

function onAfterStoreUser($user, $isnew, $success, $msg)
{
global $mainframe;


$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];

if ($isnew)
{
$message = "Test"
$subject = "Test Mail"
mail ($user['email'],$subject,$message,)
}
else
{
}
}

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 8:53 am
by ooffick
You might want to use the JMail class instead:
http://api.joomla.org/Joomla-Framework/Mail/JMail.html

Olaf

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 12:04 pm
by Star6966
so i would replace mail with JMail

would it still have the form in terms of the
JMail($user['email'],$subject,$message,)?

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 12:12 pm
by ooffick
No, it would be more like this:

Code: Select all

$mail = JFactory::getMailer();
$mail->addRecipient( $recipient );
$mail->setSender( array( $email, $name ) );
$mail->setSubject($subject );
$mail->setBody( $body );
$sent = $mail->Send();
Olaf

Re: Adding an autoresponder to a registration form

Posted: Wed Sep 09, 2009 5:30 pm
by Star6966
So to recap
Would this send an email to a user that created a new account?

Code: Select all

function onAfterStoreUser($user, $isnew, $success, $msg)
{
global $mainframe;


$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];

if ($isnew)
{
$body = "Test"
$subject = "Test Mail"
$email = $user['email']
$name = $user['name']
$recipient = $user['name']
$mail = JFactory::getMailer();
$mail->addRecipient( $recipient );
$mail->setSender( array( $email, $name ) );
$mail->setSubject($subject );
$mail->setBody( $body );
$sent = $mail->Send();
}
else
{
}
}

Re: Adding an autoresponder to a registration form

Posted: Fri Sep 18, 2009 5:51 pm
by Star6966
hey is this right

I just need to know so I can get it up and working

thanks
Star6966

Re: Adding an autoresponder to a registration form

Posted: Fri Sep 18, 2009 6:38 pm
by ooffick
Well, that looks ok. Did you try it? Does is work?

Olaf

Re: Adding an autoresponder to a registration form

Posted: Fri Sep 18, 2009 8:15 pm
by Star6966
i can't try it yet

we are still in the process of migrating to 1.5

i intend to try it as soon as the site is back up and running

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 12, 2009 8:45 pm
by Star6966
so I tried it and nothing

I am not sure if it has something to do with the way i installed it
or maybe the rest of the code

i am posting the entire code here

Code: Select all

<?php


defined('_JEXEC') or die( 'Restricted access' );


jimport('joomla.plugin.plugin');



class plgUserExample extends JPlugin 
{


	
function onAfterStoreUser($user, $isnew, $success, $msg)
{
global $mainframe;


$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];

if ($isnew)
{
$body = "Test"
$subject = "Test Mail"
$email = $user['email']
$name = $user['name']
$recipient = $user['name']
$mail = JFactory::getMailer();
$mail->addRecipient( $recipient );
$mail->setSender( array( $email, $name ) );
$mail->setSubject($subject );
$mail->setBody( $body );
$sent = $mail->Send();
}
else
{
}
}
}

that is the .php file

and here is the .xml file

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5.2" type="plugin" group="system" method="upgrade">
	<name>System - Test</name>
	<author>Erik Smith</author>
	<creationDate>September 2009</creationDate>
	<copyright>Copyright (C) 2008 Holder. All rights reserved.</copyright>
	<license>GNU General Public License</license>
	<authorEmail>[email protected]</authorEmail>
	<authorUrl></authorUrl>
	<version>1.0.1</version>
	<description>A test system plugin</description>
	<files>
		<filename plugin="example">test2.php</filename>
	</files>
	<params>
  		<param name="Test"
  		type="text"
  		default=""
  		label="Test"
  		description="An example text parameter" />
	</params>
</install>
I have the files
test.php
and
test.xml
in a zip file which i can install, but if i register a user, no response
any suggestions

Re: Adding an autoresponder to a registration form

Posted: Sun Oct 18, 2009 9:13 pm
by ooffick
and did you enable the plugin in the plugin manager?

Olaf

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 12:20 am
by Star6966
Yes I did

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 9:21 am
by ooffick
The code is missing a couple of semicolons and the Recipient is not an email address. Moreover, the name of the plugin is test2 and in the system group but your plugin class is using this plgUserExample

You can also check if the mail was send like this:
http://docs.joomla.org/JFactory/getMailer

Olaf

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 8:13 pm
by Star6966
So here is the code thus far
I am still not sure what to put for the address

Code: Select all

<?php


defined('_JEXEC') or die( 'Restricted access' );


jimport('joomla.plugin.plugin');



class test2 extends JPlugin 
{


	
function onAfterStoreUser($user, $isnew, $success, $msg)
{
global $mainframe;


$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];

if ($isnew)
{$mail =& JFactory::getMailer();
 
$config =& JFactory::getConfig();
$mail->addRecipient( $config->getValue( 'What do I put here' ) );
$mail->setSubject( 'Test message' );
$mail->setBody( 'This is an example email to test the Joomla! JFactory::getMailer() method.  Please ignore it' );
 
if ($mail->Send()) {
  echo "Mail sent successfully.";
} else {
  echo "An error occurred.  Mail was not sent.";
}

else
{
}
}
}

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 8:38 pm
by ooffick
the class is not test2, it would be more like this plgSystemTest2

or if you use the group user: plgUserTest2

Olaf

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 9:49 pm
by Star6966
anything else?

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 10:04 pm
by ooffick
Who is the supposed to be the recipient? You might want to consider to use a user plugin instead of a system plugin.

Olaf

Re: Adding an autoresponder to a registration form

Posted: Mon Oct 19, 2009 10:51 pm
by Star6966
I want the recipient to be every new user

Re: Adding an autoresponder to a registration form

Posted: Tue Oct 20, 2009 7:41 am
by ooffick
well, then you would need to use the email address in the $mail->addRecipient method:

Code: Select all

$mail->addRecipient($user['email']);

Re: Adding an autoresponder to a registration form

Posted: Tue Oct 20, 2009 9:43 am
by Star6966
what is the difference between a user plugin and a system plugin

Re: Adding an autoresponder to a registration form

Posted: Tue Oct 20, 2009 10:44 am
by ooffick