Page 1 of 1

CGCalendar: Send mail on EventAdded

Posted: Thu Feb 08, 2018 4:15 pm
by webform
I'm trying to send a mail when an event is added to CGCalendar.

It works fine when i add an event in frontend but not if i add an event in CGCalendar admin console.

Is it not possible to use EventAdded for the CGCalendar admin console or is it just frontend?

Another question; Is it somehow possible to include custom fields in the mail on EventAdded?

Re: CGCalendar: Send mail on EventAdded

Posted: Thu Feb 08, 2018 5:22 pm
by Rolf
This tutorial has a different purpose, but the method is the same and might help you:
https://www.cmscanbesimple.org/blog/adm ... tification

Re: CGCalendar: Send mail on EventAdded

Posted: Thu Feb 08, 2018 5:38 pm
by webform
Thanks Rolf

I'm not sure what triggers the EventAdded from admin in your example?

This is my UDT which works fine when adding an event to CGCalendar in frontend.

Is there something missing since no email is sent if an event is added in backend?

Code: Select all

$config = cmsms()->GetConfig();
$website_url = $config['root_url'];
$admin_url = $website_url . "/". $config['admin_dir'];
$event_title = $params['event_title'];
$event_id = $params['event_id'];
$booking_date = date('d/m-Y H:i');
$event_date_start = $params['event_date_start'];
$subject = 'Ny pladsreservation oprettet [ID: '.$event_id.']';
$smarty_data = '{$CustomGS.Pladsreservation_email}';
$email = $smarty->fetch('eval:'.$smarty_data);

$body = "En pladsreservation er oprettet i kalenderen med titel \"".$event_title ."\" og afventer godkendelse.\r\n";
$body .= "\r\n";
$body .= "For at se eller godkende pladsreservationen, log ind i infoskærm admin: ". $admin_url . ".\r\n";
$body .= "\r\n";
$body .= "Booking oprettet: ".$booking_date ."\r\n";
$body .= "ID: ".$event_id ."\r\n";
$body .= "Titel: ".$event_title ."\r\n";
$body .= "Dato/Tid: ".$event_date_start ."\r\n";
if ( $email ) 
{
$mailer = new \cms_mailer;
$mailer->SetSubject($subject);
$mailer->SetBody($body);
$mailer->AddAddress($email);
$mailer->Send();
}

audit($event_id,'CGCalendar','Ny pladsreservation: '.$event_title);