Skip to content

Instantly share code, notes, and snippets.

@morozVA
Created January 3, 2018 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morozVA/0d4c6cc83d72c156e44db9310676935e to your computer and use it in GitHub Desktop.
Save morozVA/0d4c6cc83d72c156e44db9310676935e to your computer and use it in GitHub Desktop.
evo NotiferNewUser
NotiferNewUser
Системные события OnWebSaveUser
Уведомление администратора о новой регистрации на сайте.
/**
* NotiferNewUser
*
* Уведомление о новой регистрации на сайте.
*
* @category plugin
* @version 0.2
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @internal @properties &toEmail=Почта получателя;text; &subject=Тема письма;text;
* @internal @events OnWebSaveUser
* @internal @modx_category Manager and Admin
* @author Akool
*/
$notifyTpl = '
<p>На сайте [+site_name+] добавлен новый веб-пользователь.</p>
<p>id пользователя: '. $userid .'</p>
<p>Имя пользователя: '. $modx->db->escape($modx->stripTags($_POST['newusername'])) .'</p>
<p>Email пользователя: [+useremail+]</p>';
$docid = 66; // id документа tv которого так хочется
$tv = $modx->getTemplateVar('add_user_email', '*', $docid);
$toEmail = $tv['value'];
//$toEmail = 'cadaver@tut.by';
$subject = isset($subject) ? $subject : 'Новая регистрация на сайте'; // тема письма
if ($modx->Event->name == 'OnWebSaveUser') {
$uemail = isset($useremail) ? $useremail : ($_POST['email'] != '' ? $modx->db->escape($modx->stripTags($_POST['email'])) : '');
if ($mode != 'new' || $uemail == '' || !filter_var($uemail, FILTER_VALIDATE_EMAIL)) return;
$res = $modx->db->select("id", $modx->getFullTableName('web_users'),"","id DESC",1 );
if($modx->db->getRecordCount($res)) {
$id = $modx->db->getValue($res);
$userid = $id + 1;
}
require_once MODX_BASE_PATH.'/manager/includes/controls/class.phpmailer.php';
$notification = str_replace('[+useremail+]', $uemail, $notifyTpl);
$notification = str_replace('[+site_name+]', $modx->config['site_name'], $notification);
$Notify = new PHPMailer();
$Notify->CharSet = $modx->config['modx_charset'];
$Notify->IsHTML(true);
$Notify->From = $modx->config['emailsender'];
$Notify->FromName = $modx->config['site_name'];
$Notify->Subject = $subject;
$Notify->Body = $notification;
$Notify->AddAddress($toEmail);
if (!$Notify->Send()) {
$modx->logEvent(89, 1, 'Не удалось отправить письмо на адрес '.$toEmail.' о новом пользователе.', 'NotiferNewUser');
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment