Use Events to Send an Email when a Page is Edited?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
cyberman

Re: Use Events to Send an Email when a Page is Edited?

Post by cyberman »

Maybe there's something wrong with your mail() function?
SimonSchaufi

Re: Use Events to Send an Email when a Page is Edited?

Post by SimonSchaufi »

no no. like i said before, when i change a page and send an email, IT WORKS!!! But when adding a new user, it doesnt work!
SimonSchaufi

Re: Use Events to Send an Email when a Page is Edited?

Post by SimonSchaufi »

IT WORKS!!!

My mistake was a dash in the UDT name:

send-mail

is not working (warum auch immer)

That is the reason why the other method with the cmsmailer was not working as well!
Last edited by SimonSchaufi on Tue Aug 14, 2007 7:24 pm, edited 1 time in total.
cyberman

Re: Use Events to Send an Email when a Page is Edited?

Post by cyberman »

SimonSchaufi wrote: send-mail

is not working (warum auch immer)
You can read the reason here

http://forum.cmsmadesimple.org/index.ph ... 205.0.html

(in german)
SimonSchaufi

Re: Use Events to Send an Email when a Page is Edited?

Post by SimonSchaufi »

Here my solution (a bit tuned ;D ):

Make sure you dont save it with a dash in the UDT name!

Code: Select all

function validate_email($email){
   $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
   if(eregi($exp,$email)){
      if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
        return true;
      }else{
        return false;
      }
   }else{
      return false;
   }
}

global $gCms;
$sitename = get_site_preference('sitename', 'My Homepage'); /* If sitename is not set, use My Homepage */

$newuser =& $params['user'];

$bodytext = 'This is your new user account information:

First Name: '.$newuser->firstname.'
Last Name: '.$newuser->lastname.'

Username: '.$newuser->username.'
Password: '.$_POST["password"].'

Email: '.$newuser->email.'

Login here: '.$gCms->config["root_url"].DIRECTORY_SEPARATOR.$gCms->config["admin_dir"].'

After login please change your password here: My Preferences -> My Account!';

if($newuser->email != "" && validate_email($newuser->email)){
  $cmsmailer =& $gCms->modules['CMSMailer']['object'];
  $cmsmailer->AddAddress($newuser->email);
  $cmsmailer->SetBody($bodytext);
  $cmsmailer->IsHTML(false);
  $cmsmailer->SetSubject($sitename.' User Account Information');
  $cmsmailer->Send();
}
There is no possibility to get the password as plain text so you need to catch it from the POST var.

If nobody has any other suggestions, i will post it in the wiki
Last edited by SimonSchaufi on Wed Aug 15, 2007 11:47 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Use Events to Send an Email when a Page is Edited?

Post by calguy1000 »

When working with events, each event will return different items in $params.  You have to check for this on a handler, by handler basis.

i.e: $params['content'] may not exist for every event, it may be something different, and even if it is..... it may not be a reference to an object, etc.

There is help for each event that describes what parameters are delivered (somewhat), and this would be a great place to start.  After that, I'd start with: 

print_r( $params ); die();

for every event handler, and then go from there.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Use Events to Send an Email when a Page is Edited?

Post by calguy1000 »

I just looked at the source, and a skilled module developer could write a module, using Events to add versioning into CMS Made Simple.  It's a very nice system, the Events give CMS Made simple an extreme amount of flexibility and customising capability with just a bit of programming knowledge.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
OCStingFan
Forum Members
Forum Members
Posts: 12
Joined: Tue Nov 06, 2007 10:21 pm

Re: Use Events to Send an Email when a Page is Edited?

Post by OCStingFan »

How could this code (i.e the UDT in the wiki called "Send Email Notification on Page Change") be set up to send a notification to a dynamic group of recipients rather than an individual or unchanging group of recipients? I'm developing a site now for a school and the teachers will have their own pages to post notes for parents to check. An existing web-based solution which I am trying to emulate in the CMS allows the teacher to send a notification when their page is updated to the parents' email addresses. If a mailing list can be set up inside CMSMS (such as in the NMS module), can that be a basis for sending an email notification using Events?
cyberman

Re: Use Events to Send an Email when a Page is Edited?

Post by cyberman »

Maybe you should use FrontendUsers module?

It has an own event if user data are changed ...
Locked

Return to “CMSMS Core”