Page 2 of 3
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 27, 2007 11:22 pm
by calguy1000
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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 27, 2007 11:47 pm
by monghidi
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:
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();
And the email reads:
Re: Use Events to Send an Email when a Page is Edited?
Posted: Sat Jul 28, 2007 9:26 am
by SimonSchaufi
this works: (you mixed some ' and ")
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();
Re: Use Events to Send an Email when a Page is Edited?
Posted: Mon Jul 30, 2007 1:18 pm
by monghidi
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):
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
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!
Re: Use Events to Send an Email when a Page is Edited? [SOLVED]
Posted: Wed Aug 01, 2007 4:25 am
by monghidi
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!
Re: Use Events to Send an Email when a Page is Edited?
Posted: Wed Aug 01, 2007 4:30 am
by FantomCircuit
Horay! useful data in the wiki!

Re: Use Events to Send an Email when a Page is Edited?
Posted: Wed Aug 01, 2007 11:10 am
by SimonSchaufi
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?
Re: Use Events to Send an Email when a Page is Edited?
Posted: Wed Aug 01, 2007 11:20 pm
by FantomCircuit
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?
Posted: Mon Aug 13, 2007 6:59 am
by SimonSchaufi
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:
$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();
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Aug 14, 2007 7:15 am
by SimonSchaufi
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?
Posted: Tue Aug 14, 2007 1:08 pm
by cyberman
calguy1000 wrote:
if that doesn't work.... you need to var_dump or print_r the value of $params into your emails until everything works.
That's my solution
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);
Result is a mail with this content
Content 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
If you only wanna know a single value (for instance name of modified page, means value of mName) replace
with
Code: Select all
if ($key == 'mName') $message = "Modified page: $value \n";
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Aug 14, 2007 1:21 pm
by SimonSchaufi
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
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Aug 14, 2007 1:43 pm
by calguy1000
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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Aug 14, 2007 1:45 pm
by cyberman
SimonSchaufi wrote:
Well, there was a misunderstanding.
No, there was no misunderstanding - I've posted only my solution for this topic

.
The email works when a page is changed but it doenst work before/after creating a new user.
Change
Code: Select all
foreach($params['content'] as $key=>$value)
to
Code: Select all
foreach($params['user'] as $key=>$value)
in my posted script and it works.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Aug 14, 2007 2:23 pm
by SimonSchaufi
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