Use Events to Send an Email when a Page is Edited?
-
- 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?
after looking at Search's DoEvent callback
the params are sent as a hash (associative array).
So try adding this at the top:
$content =& $params['content'];
if that doesn't work.... you need to var_dump or print_r the value of $params into your emails until everything works.
the params are sent as a hash (associative array).
So try adding this at the top:
$content =& $params['content'];
if that doesn't work.... you need to var_dump or print_r the value of $params into your emails until everything works.
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.
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.
Re: Use Events to Send an Email when a Page is Edited?
WOW! you all are fast. Let me say now that I appreciate all your help even if we never get this working! 
Anyhow.. I tried FantomCircuit's suggestion (swapping single/double quotes). No go, no difference.
Next, I tried Calguy's suggestion to add $content =& $params['content']; at the top. No difference.
I set $bodytext to be print_r($params) and got this in the email body: print_r(Array)
SO, somehow we are still not grabbing what we need, populating $bodytext with it, and printing it into the body of the message.
Any more suggestions? I'm feeling pretty determined!
For reference, my UDT now looks like this:
And the email reads:

Anyhow.. I tried FantomCircuit's suggestion (swapping single/double quotes). No go, no difference.
Next, I tried Calguy's suggestion to add $content =& $params['content']; at the top. No difference.
I set $bodytext to be print_r($params) and got this in the email body: print_r(Array)
SO, somehow we are still not grabbing what we need, populating $bodytext with it, and printing it into the body of the message.
Any more suggestions? I'm feeling pretty determined!
For reference, my UDT now looks like this:
Code: Select all
global $gCms;
$content =& $params['content'];
$bodytext = "
Page Name: '.$content->Name().'
";
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress('emailaddress@anisp.com');
$cmsmailer->SetBody($bodytext);
$cmsmailer->IsHTML(false);
$cmsmailer->SetSubject('Page Change Notification');
$cmsmailer->Send();
Code: Select all
Page Name: '.().'
Re: Use Events to Send an Email when a Page is Edited?
this works: (you mixed some ' and ")
I have included an URL to it.
for others: set the from address in the mailer module preferences!
I have included an URL to it.
for others: set the from address in the mailer module preferences!
Code: Select all
$content =& $params['content'];
$bodytext = '
A page has been changed.
Page ID: '.$content->Id().'
Page Name: '.$content->Name().'
Page Alias: '.$content->Alias().'
Page Type: '.$content->Type().'
Page Owner: '.$content->Owner().'
Created: '.$content->GetCreationDate().'
Modified: '.$content->GetModifiedDate().'
URL: '.$content->GetURL();
global $gCms;
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress('yourem@il.com');
$cmsmailer->SetBody($bodytext);
$cmsmailer->IsHTML(false);
$cmsmailer->SetSubject('Page Change Notification');
$cmsmailer->Send();
Last edited by SimonSchaufi on Sat Jul 28, 2007 9:45 am, edited 1 time in total.
Re: Use Events to Send an Email when a Page is Edited?
Yes! thank you SimonSchaufi, Calyguy, FantomCircuit, and others who helped.
This works well enough to serve as a base example for sending an email when a page edit is saved. I plan to add it to the documentation as soon as I get a chance, here: http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here.
In the email that is sent, the output of this UDT/Event reads like this (note that I made some substitutions to show it as generic):
It would be much better if the "Page Owner" didn't show the ID number, but instead showed the name or username of the person who made the edit. I made some attempts at this a bit without success.
Anyone able to take a stab at collecting the name of the user who made the modification?
Thanks again!
This works well enough to serve as a base example for sending an email when a page edit is saved. I plan to add it to the documentation as soon as I get a chance, here: http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here.
In the email that is sent, the output of this UDT/Event reads like this (note that I made some substitutions to show it as generic):
Code: Select all
A page has been changed.
Page ID: 120
Page Name: Name of the Page
Page Alias: Alias of the page
Page Type: content
Page Owner: 1
Page Created: 2007-07-26 01:18:22
Modified on: 2007-07-28 12:50:26
URL: http://www.domainname.com/index.php?page=pagealias
Anyone able to take a stab at collecting the name of the user who made the modification?
Thanks again!
Re: Use Events to Send an Email when a Page is Edited? [SOLVED]
This UDT/Event combo works now and I *was* able to get the username of the user who made the modification. I've only tested it on my current cmsms1.08 with CMSMailer module 1.73.10.
I have added a quick 'how-to' on the documentation wiki here:
http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here#Send_Email_Notification_on_Page_Change
Thanks to all who pitched in, and good luck!
I have added a quick 'how-to' on the documentation wiki here:
http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here#Send_Email_Notification_on_Page_Change
Thanks to all who pitched in, and good luck!
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Use Events to Send an Email when a Page is Edited?
Horay! useful data in the wiki! 

Re: Use Events to Send an Email when a Page is Edited?
My next question doesnt really fit to the title but i would like to inform new registered users via the admin panel using UDT. How can i get the Email, Password and the Username to send it via Email?
Last edited by SimonSchaufi on Wed Aug 01, 2007 11:28 am, edited 1 time in total.
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Use Events to Send an Email when a Page is Edited?
Hmm, that's an excellent idea - one that I have longed for in the past. I'll have a look into it.
Re: Use Events to Send an Email when a Page is Edited?
I looked at the source how a new user is stored in the database. the problem is how to get the password because it is stored as md5, so you need to get it via $_POST, am i right?
do i need something like this as well:
i played a bit but i was not yet successful with this:
do i need something like this as well:
?$content =& $params['content'];
i played a bit but i was not yet successful with this:
Code: Select all
$bodytext = '
First Name: '.$newuser->firstname.'
Last Name: '.$newuser->lastname.'
Username: '.$newuser->username.'
Password: ???
Email: '.$newuser->email.'';
//mail("email@example.com", "New User Account Information", $bodytext);
global $gCms;
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress('email@example.com');
$cmsmailer->SetBody($bodytext);
$cmsmailer->IsHTML(false);
$cmsmailer->SetSubject('New User Account Information');
$cmsmailer->Send();
Last edited by SimonSchaufi on Mon Aug 13, 2007 9:19 pm, edited 1 time in total.
Re: Use Events to Send an Email when a Page is Edited?
somehow not even an email with a bodytext like "test" is sent. i switched on the debug and the UDT is called but somehow no email is sent even though i am using the same code like the one i posted before.
Re: Use Events to Send an Email when a Page is Edited?
That's my solutioncalguy1000 wrote: if that doesn't work.... you need to var_dump or print_r the value of $params into your emails until everything works.
Code: Select all
$from = "From: system <system@yourdomain.com>\r\n";
$subject = "Content was modified";
$to = "my_email@domain.com";
$message = "Content was modified with the following data: \n\n";
foreach($params['content'] as $key=>$value)
{
$message .= "$key => $value \n";
}
@mail($to, $subject, $message, $from);
If you only wanna know a single value (for instance name of modified page, means value of mName) replaceContent was modified with the following data:
mId => 120
mName => GoogleContent Feed
mType => content
mOwner => 1
mProperties => Object
mPropertiesLoaded => 1
mParentId => 108
mOldParentId => 108
mTemplateId => 17
mItemOrder => 16
mOldItemOrder => 16
mMetadata =>
mTitleAttribute =>
mAccessKey =>
mTabIndex =>
mHierarchy =>
mIdHierarchy => 120
mHierarchyPath => gcontent-feed
mMenuText => GoogleContent Feed
mActive => 1
mAlias => gcontent-feed
mOldAlias => gcontent-feed
mCachable => 1
mPreview => 1
mShowInMenu => 1
mDefaultContent =>
mMarkup => html
mLastModifiedBy => 1
mCreationDate => 2007-07-12 10:22:53
mModifiedDate => 2007-08-14 15:04:51
mAdditionalEditors => Array
mReadyForEdit => 1
additionalContentBlocks => Array
addtContentBlocksLoaded => 1
mChildCount => 0
Code: Select all
$message .= "$key => $value \n";
Code: Select all
if ($key == 'mName') $message = "Modified page: $value \n";
Re: Use Events to Send an Email when a Page is Edited?
Well, there was a misunderstanding. The email works when a page is changed but it doenst work before/after creating a new user.
I am using 1.0.8
I am using 1.0.8
Last edited by SimonSchaufi on Tue Aug 14, 2007 2:11 pm, edited 1 time in total.
-
- 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?
Well, after doing some quick checks in the code..... The AddUserPost event receives a User object in its params
so you'd just need to do something like:
$newuser =& $params['user'];
I looked in admin/adduser.php and lib/classes/class.user.inc.php to find this stuff out.
so you'd just need to do something like:
$newuser =& $params['user'];
I looked in admin/adduser.php and lib/classes/class.user.inc.php to find this stuff out.
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.
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.
Re: Use Events to Send an Email when a Page is Edited?
No, there was no misunderstanding - I've posted only my solution for this topicSimonSchaufi wrote: Well, there was a misunderstanding.

ChangeThe email works when a page is changed but it doenst work before/after creating a new user.
Code: Select all
foreach($params['content'] as $key=>$value)
Code: Select all
foreach($params['user'] as $key=>$value)
Re: Use Events to Send an Email when a Page is Edited?
still no email going to my mailbox
the event is in the AddUserPost Eventhandler. i am using 1.0.8. even a single mail via mail(...) is not working
the event is in the AddUserPost Eventhandler. i am using 1.0.8. even a single mail via mail(...) is not working