Send multiple emails when page is edited?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
wolphy
Forum Members
Forum Members
Posts: 33
Joined: Fri Sep 19, 2008 2:26 pm

Send multiple emails when page is edited?

Post by wolphy »

what's the syntax to use when listing multiple emails in an "alert" UDT?

i have this for a single address:
mail('me@here.com','page updated','the demo page has been changed');

how do i add "him@there.com" and "her@there.com" to the above UDT?
NaN

Re: Send multiple emails when page is edited?

Post by NaN »

Why don't you use the one suggested here:

http://wiki.cmsmadesimple.org/index.php ... age_Change

It uses the CMSms Mailer Module that comes with the standard installation.
If you change it like this:

Code: Select all


global $gCms;
$content =& $params['content'];

$editedby = $gCms->variables['username'];

$bodytext = '
A page on the web site has been changed.

Page Name: '.$content->Name().'
Page Alias: '.$content->Alias().'
Page Type: '.$content->Type().'
Page Created: '.$content->GetCreationDate().'
Modified on: '.$content->GetModifiedDate().'
Modified by: '.$editedby.'
Page URL: '.$content->GetURL();

$cmsmailer =& $gCms->modules['CMSMailer']['object'];

$addresses = array();
$addresses[0] = "your_1st_address@somewhere.com";
$addresses[1] = "your_2nd_address@somewhere.com";
$addresses[2] = "your_3rd_address@somewhere.com";

...

foreach($addresses as $one_address) {

    $cmsmailer->AddAddress($one_address);
    $cmsmailer->SetBody($bodytext);
    $cmsmailer->IsHTML(false);
    $cmsmailer->SetSubject('Page change notification--' .$content->Name());
    $cmsmailer->Send();
    $cmsmailer->ClearAddresses();

}

you can send a "page-change-notification" to as many emails as you wish by just adding new addresses to the $addresses array().
I'm using a similar code snippet in my FEU Mailer modul that send emails to all frontend users of selected groups.

I'm not sure at the moment how to realize but it should be easy to advance that UDT to get the page admins emailaddresses automatically so that you don't need to fill in the addresses in the UDT by yourself.

EDIT:
I had a typo error in the foreach-loop ($addesses instead of $addresses).
Last edited by NaN on Thu Feb 26, 2009 4:55 am, edited 1 time in total.
Post Reply

Return to “Developers Discussion”