<p>You'll need to create a small custom plugin to do this. You can create the scaffolding for a plugin using the excellent <a href="https://pluginfactory.io" rel="nofollow noreferrer">Plugin Factory</a> site. You'll just need to create a basic plugin, with none of the component options selected.</p>

<p>What you need to do is to use <a href="https://craftcms.com/docs/plugins/hooks-and-events#events" rel="nofollow noreferrer">Craft's events</a> to detect when a new user is created using the Control Panel.</p>

<p>The specific event you need to listen for is the <a href="https://craftcms.com/docs/plugins/events-reference#users-onActivateUser" rel="nofollow noreferrer"><code>users.onActivateUser</code> event</a>.</p>

<p>You'll need something like this in your plugin's <code>init()</code> method:</p>

<pre><code>/**
 * @return mixed
 */
public function init()
{
    // When creating new users through the control panel, send them a password reset email.
    craft()-&gt;on('users.activateUser', function(Event $event) {

        // only fire if this is a CP request
        if (craft()-&gt;request-&gt;isCpRequest()) {

            // retrieve the userModel from the event
            $user = $event-&gt;params['user'];

            // send password reset email
            craft()-&gt;users-&gt;sendPasswordResetEmail($user);
        }
    });
}
</code></pre>

CC BY-SA 3.0
2017-02-14T09:14:48.593Z
Thank you! While it does correctly send the "password reset" email to the user created user over the CP, it seems that the password reset url is invalid (Invalid verification code error). The weird part is that when I send the password reset directly from the CP, the link in the email works as intended. Do you have any idea why?
Jose Manosalvas
CC BY-SA 3.0
2017-02-14T09:33:59.200Z
When you generate a new password reset link, all previous links are automatically invalidated. So if one is generated by the code above when the user is first created, then you send a second one via the CP, the first one will no longer be valid. Is that what might have happened?
Steve Rowling
CC BY-SA 3.0
2017-02-14T09:48:22.420Z
After taking a look in the DB, it seems that "verificationCode" stays NULL even after sending the email and is the reason why the link won't work. Could this be because of "activateUser" function deleting the verification code, firing after the saveUser event?
Jose Manosalvas
CC BY-SA 3.0
2017-02-14T09:53:31.627Z
Sorry @Steve, didn't saw your answer before. What I meant is that the email link threw an error even before generating a new password reset link from the CP (I did so to be sure that the password reset pages were working).
Jose Manosalvas
CC BY-SA 3.0
2017-02-14T10:15:04.960Z
Yes, I think you're right, it could be that `activateUser()` is deleting the verification code. I've modified the code in my answers to use the `users.activateUser` event instead. Try that and let me know if it works!
Steve Rowling
CC BY-SA 3.0
2017-02-13T15:50:01.300Z
2017-02-14T10:14:28.297Z
2017-02-14T10:14:28.297Z
Steve Rowling
<p>We have a website that allows users to register themselves with a front-end registration form, and are automatically logged-in once they're done (thanks to <code>autoLoginAfterAccountActivation</code>).</p>

<p>But we also need to create users directly from the Control Panel on a regular basis. 
Since autoLogin doesn't work with the "Verify email addresses?" user setting, I'm looking for a way to send the activation email only to the users that we have manually created over the Control Panel, so they're able to set a password.</p>

<p>Is there any way to send the verification email only to users created over the Control Panel?</p>

<users><control-panel><emails><registration>
Send activation email only for users created over the Control Panel
# Send activation email only for users created over the Control Panel

(Asked by: username_0 on 2017-02-13)

We have a website that allows users to register themselves with a front-end registration form, and are automatically logged-in once they're done (thanks to `autoLoginAfterAccountActivation`).

But we also need to create users directly from the Control Panel on a regular basis.
Since autoLogin doesn't work with the "Verify email addresses?" user setting, I'm looking for a way to send the activation email only to the users that we have manually created over the Control Panel, so they're able to set a password.

Is there any way to send the verification email only to users created over the Control Panel?

**Tags:** users, control-panel, emails, registration

---

## 1 answers

### Answer by username_1 on 2017-02-13. Score: 1 | Accepted answer

You'll need to create a small custom plugin to do this. You can create the scaffolding for a plugin using the excellent Plugin Factory site. You'll just need to create a basic plugin, with none of the component options selected.
What you need to do is to use Craft's events to detect when a new user is created using the Control Panel.
The specific event you need to listen for is the users.onActivateUser event.
You'll need something like this in your plugin's init() method:
/**
 * @return mixed
 */
public function init()
{
    // When creating new users through the control panel, send them a password reset email.
    craft()->on('users.activateUser', function(Event $event) {

        // only fire if this is a CP request
        if (craft()->request->isCpRequest()) {

            // retrieve the userModel from the event
            $user = $event->params['user'];

            // send password reset email
            craft()->users->sendPasswordResetEmail($user);
        }
    });
}

> **Comments:**
> **username_0**: Thank you! While it does correctly send the "password reset" email to the user created user over the CP, it seems that the password reset url is invalid (Invalid verification code error). The weird part is that when I send the password reset directly from the CP, the link in the email works as intended. Do you have any idea why?  
> **username_1**: When you generate a new password reset link, all previous links are automatically invalidated. So if one is generated by the code above when the user is first created, then you send a second one via the CP, the first one will no longer be valid. Is that what might have happened?  
> **username_0**: After taking a look in the DB, it seems that "verificationCode" stays NULL even after sending the email and is the reason why the link won't work. Could this be because of "activateUser" function deleting the verification code, firing after the saveUser event?  
> **username_0**: Sorry @Steve, didn't saw your answer before. What I meant is that the email link threw an error even before generating a new password reset link from the CP (I did so to be sure that the password reset pages were working).  
> **username_1**: Yes, I think you're right, it could be that `activateUser()` is deleting the verification code. I've modified the code in my answers to use the `users.activateUser` event instead. Try that and let me know if it works!  

---

