[SOLVED] UDT To Send Email To New User From Self Registration
Posted: Mon Jun 28, 2010 1:26 pm
Hey,
I couldn't find a UDT in the forum to automatically send an email to a new user once they have registered with SelfRegistration so I tweaked a different one I found. I thought I would post it here in case anyone else was looking for the same thing.
1. Create A UDT called "New_User" or anything you like.
2. Copy & Paste the below code into the UDT. Be sure to make the appropriate changes to tailor it for your setup. I use the standard Username as the email but you may be using something else.
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
global $gCms;
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
global $gCms;
$feu = MyGetModuleInstance('FrontEndUsers');
if ($feu == FALSE)
return false;
//Get User
$feu_user = $feu->GetUserInfo($params['id']);
//Do they really exist? Why are we here anyway?
if ($feu_user)
{
//use CMSMailer module to send mail
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress($feu->GetUserName($params['id']),$feu->GetUserPropertyFull('Username', $params['id']));
$cmsmailer->SetFrom('FROM EMAIL ADDRESS HERE');
$cmsmailer->SetFromName('FROM NAME HERE');
$cmsmailer->SetBody('EMAIL MESSAGE HERE');
$cmsmailer->IsHTML(true);
$cmsmailer->SetSubject('EMAIL SUBJECT HERE');
$cmsmailer->Send();
}
3. Add the UDT to the onUserRegistered event in Event Manager.
That's it.
I couldn't find a UDT in the forum to automatically send an email to a new user once they have registered with SelfRegistration so I tweaked a different one I found. I thought I would post it here in case anyone else was looking for the same thing.
1. Create A UDT called "New_User" or anything you like.
2. Copy & Paste the below code into the UDT. Be sure to make the appropriate changes to tailor it for your setup. I use the standard Username as the email but you may be using something else.
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
global $gCms;
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
global $gCms;
$feu = MyGetModuleInstance('FrontEndUsers');
if ($feu == FALSE)
return false;
//Get User
$feu_user = $feu->GetUserInfo($params['id']);
//Do they really exist? Why are we here anyway?
if ($feu_user)
{
//use CMSMailer module to send mail
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress($feu->GetUserName($params['id']),$feu->GetUserPropertyFull('Username', $params['id']));
$cmsmailer->SetFrom('FROM EMAIL ADDRESS HERE');
$cmsmailer->SetFromName('FROM NAME HERE');
$cmsmailer->SetBody('EMAIL MESSAGE HERE');
$cmsmailer->IsHTML(true);
$cmsmailer->SetSubject('EMAIL SUBJECT HERE');
$cmsmailer->Send();
}
3. Add the UDT to the onUserRegistered event in Event Manager.
That's it.