Adding an autoresponder to a registration form

For Joomla! 1.0 Coding related discussions.
Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Adding an autoresponder to a registration form

Postby Star6966 » Sun Sep 06, 2009 4:22 pm

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

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Sun Sep 06, 2009 7:05 pm

Hi,

which version of Joomla do you have?

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Sep 07, 2009 4:55 pm

1.0

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Mon Sep 07, 2009 9:09 pm

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
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Tue Sep 08, 2009 12:07 am

ok
how would I do it in 1.5?

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Tue Sep 08, 2009 9:28 am

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
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Wed Sep 09, 2009 1:09 am

Ok

and how would I get it to send a message

I am pretty new at this kind of programing

Thanks alot

Star6966

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Wed Sep 09, 2009 1:39 am

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
{
}
}

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Wed Sep 09, 2009 8:53 am

You might want to use the JMail class instead:
http://api.joomla.org/Joomla-Framework/Mail/JMail.html

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Wed Sep 09, 2009 12:04 pm

so i would replace mail with JMail

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

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Wed Sep 09, 2009 12:12 pm

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
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Wed Sep 09, 2009 5:30 pm

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
{
}
}

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Fri Sep 18, 2009 5:51 pm

hey is this right

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

thanks
Star6966

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Fri Sep 18, 2009 6:38 pm

Well, that looks ok. Did you try it? Does is work?

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Fri Sep 18, 2009 8:15 pm

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

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Oct 12, 2009 8:45 pm

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

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Sun Oct 18, 2009 9:13 pm

and did you enable the plugin in the plugin manager?

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Oct 19, 2009 12:20 am

Yes I did

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Mon Oct 19, 2009 9:21 am

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
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Oct 19, 2009 8:13 pm

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
{
}
}
}

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Mon Oct 19, 2009 8:38 pm

the class is not test2, it would be more like this plgSystemTest2

or if you use the group user: plgUserTest2

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Oct 19, 2009 9:49 pm

anything else?

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Mon Oct 19, 2009 10:04 pm

Who is the supposed to be the recipient? You might want to consider to use a user plugin instead of a system plugin.

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Mon Oct 19, 2009 10:51 pm

I want the recipient to be every new user

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Tue Oct 20, 2009 7:41 am

well, then you would need to use the email address in the $mail->addRecipient method:

Code: Select all

$mail->addRecipient($user['email']);
Olaf Offick - Global Moderator
http://learnskills.org

Star6966
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Sep 06, 2009 4:11 pm

Re: Adding an autoresponder to a registration form

Postby Star6966 » Tue Oct 20, 2009 9:43 am

what is the difference between a user plugin and a system plugin

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11070
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Adding an autoresponder to a registration form

Postby ooffick » Tue Oct 20, 2009 10:44 am

Olaf Offick - Global Moderator
http://learnskills.org


Return to “Joomla! 1.0 Coding”

Who is online

Users browsing this forum: No registered users and 2 guests