I have a client that wants to get notified whenever someone registers on their website.
How can I do this, is there some kind of plugin? If not how would I go about doing this?
I have a client that wants to get notified whenever someone registers on their website.
How can I do this, is there some kind of plugin? If not how would I go about doing this?
I have done something very similar. You'll want to create a plugin for this.
In my case, I am validating email addresses so I was checking against the onBeforeActivateUser event. If you are not validating email addresses, @Lindsey D' answer is where you want to go.
Either way, they will look about like this:
I created a plugin called accounts.
MyPlugin.php
public function init()
{
/**
* Event listener for activating a user.
*
* @param Event $event
*/
craft()->on('users.onBeforeActivateUser', function (Event $event) {
$user = $event->params['user'];
craft()->accounts->onSendNotificationEmail($user);
});
}
MyService.php
/**
* Sends a notification email.
*
* @param $user
* @return bool
*/
public function onSendNotificationEmail($user)
{
$recipient = $user->email; // get the email address passed in
$email = new EmailModel();
$message = '<!DOCTYPE html><html><title>My Title</title><head>';
$message .= '<body>';
$message .= '<table width="800" border="0" cellpadding="0" cellspacing="0">';
$message .= '<tr><td style="text-align: center;">LOGO/BRANDING </td></tr>';
$message .= '</table>';
$message .= '<p>Hello,<br>There has been a new account created on the website.</p>';
$message .= '<p>...your message here...</p>';
$message .= '</body></html>';
$email->subject = 'New Account Created';
$email->body = $message;
try {
$email->toEmail = $recipient;
craft()->email->sendEmail($email);
} catch (\Exception $e) {
return false;
}
}
I'm sure there is a cleaner way to get your email body into the CP itself and allow the admin to change the message easily, but this works quick/well.
I don't think a plugin is available to do this specifically but you could write your own plugin and listen to the onAssignUserToDefaultGroup event and send an e-mail from there in your plugin.
Sending an e-mail can be done through the EmailService
isNewUserbefore sending the email. – Lindsey D Jun 09 '17 at 17:29