Quote from: jgrant at May 16, 2013, 09:23 PMUseful thread! I was just needing to do this very thing.
In the process() method of the LoginConfirmRegisterController class (ConfirmRegister.php) you can get the user name with $this->user->get('username'). Also $modx should be $this->modx.
I modified the code the code to fix these things and also added a few features for the project I'm working on:
$username = $this->user->get('username');
$usergroups = implode($this->user->getUserGroupNames(), ', '); // I also want to include what groups a person has signed up for
$siteurl = $this->modx->getOption('site_url') . ltrim(MODX_MANAGER_URL, '/') . 'index.php?a=56'; // a link to 'Manage Users' in the Manager
$adminEmail = $this->modx->getOption('admin.email'); // I created an admin.email setting in System Settings
$this->modx->getService('mail', 'mail.modPHPMailer');
$this->modx->mail->set(modMail::MAIL_BODY, "put your email body in here, or better, get it from a chunk");
$this->modx->mail->set(modMail::MAIL_FROM, $adminEmail);
$this->modx->mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('site_name'));
$this->modx->mail->set(modMail::MAIL_SENDER, $adminEmail);
$this->modx->mail->set(modMail::MAIL_SUBJECT, 'subject goes here');
$this->modx->mail->setHTML(true); // HTML email
$this->modx->mail->address('to', $adminEmail, $adminEmail);
$this->modx->mail->address('reply-to', $adminEmail);
$sent = $this->modx->mail->send();
Jgrant first off this is and awesome addition to this post! I was able to send an e-mail during testing after your tweaks so it works. But I have a few easy questions:
As far as this coding:
$this->modx->mail->set(modMail::MAIL_BODY, "put your email body in here, or better, get it from a chunk");
If I create a chunk for this e-mail (as you recommend) that is called: adminNotice how would I put this chunk into this coding. Like this:
$this->modx->mail->set(modMail::MAIL_BODY, "[[$adminNotice]] ");
?
Second, I notice that you call up the site URL and the username, but they do not show in the e-mail that is being sent. Would I add them to the chunk? Like this: [[+siteurl]] and [[+username]]? I don't know how to get the URL and username into the e-mail properly. It looks like you define them, but I don't know how to call them in the e-mail. Sorry for the simple questions.