<p>I fixed it by putting the Event::on inside the init</p>

CC BY-SA 4.0
2023-03-19T09:24:53.473Z
2023-03-19T09:24:53.473Z
aren
<p>You haven’t said what is not working, which makes it difficult to answer your question. Please ensure that your email settings are correctly configured and working. Also note that you’ve chosen to use the <code>EVENT_BEFORE_ACTIVATE_USER</code> event, which is triggered before a user is activated.</p>
<p>The event handler should work as follows:</p>
<pre class="lang-php prettyprint-override"><code>        Event::on(
            Users::class,
            Users::EVENT_BEFORE_ACTIVATE_USER,
            function (UserEvent $event) {
                $user = $event-&gt;user;
                Craft::$app-&gt;getMailer()
                    -&gt;compose()
                    -&gt;setTo('test@test.com')
                    -&gt;setSubject('New User')
                    -&gt;setHtmlBody('New User: ' . $user-&gt;firstName . ' ' . $user-&gt;LastName)
                    -&gt;send();
            }
        );
</code></pre>

CC BY-SA 4.0
2023-03-08T02:16:22.153Z
To expand on Ben's answer - there's a test email button in the email configuration settings. Try that to make sure email is working at all, or if it's just emails being sent from this module
cherrykoda
CC BY-SA 4.0
2023-03-09T18:18:49.000Z
Hi guys thanks for responding, my emails are working since I'm using some contact forms which are working fine, it is indeed the emails are not sent from this module
aren
CC BY-SA 4.0
2023-03-10T15:42:14.997Z
@aren Can you check the log files in `/storage/logs` for errors?
Ben Croker
CC BY-SA 4.0
2023-03-12T08:38:07.060Z
@BenCroker hey I added the logs to my post
aren
CC BY-SA 4.0
2023-03-12T09:16:54.940Z
@BenCroker it looks like it's not calling the module
aren
CC BY-SA 4.0
2023-03-14T03:14:06.250Z
Are you bootstrapping the module in `app.php`?
Ben Croker
CC BY-SA 4.0
2023-03-18T08:55:47.423Z
@BenCroker yes it is in bootstrap
aren
CC BY-SA 4.0
2023-03-19T07:31:52.160Z
Did you do `composer dump-autoload`? Also can you try `var_dump('test')` after `parent::init()` in your module, will it dump 'test' on the site? If not then your module is not active.
RomanAvr
CC BY-SA 4.0
2023-03-19T09:09:30.573Z
@RomanAvr yes i did a dump auto load and var dump is showing on the site
aren
CC BY-SA 4.0
2023-03-19T09:24:16.360Z
Guys thanks for your effort everyone I got the module working by putting the event in the init instead of in the attacheventhandlers
aren
CC BY-SA 4.0
2023-03-06T15:35:55.323Z
2023-03-06T15:35:55.323Z
Ben Croker
<p>I'm trying to make a craft module, which sends a mail to the admin whenever a new user registers.</p>
<p>Somehow I'm not able to get this work, anyone knows how to solve this?
The module is not able to send an email.</p>
<p>I used the command line craft commands to setup the structure of this module.</p>
<p>the module is called user registration mails</p>
<pre><code>&lt;?php

namespace modules\userregistrationmails;

use Craft;
use yii\base\Module as BaseModule;
use yii\base\Event;
use craft\services\Users;
use craft\events\UserEvent;
use craft\events\RegisterTemplateRootsEvent;
use craft\events\TemplateEvent;
use craft\i18n\PhpMessageSource;
use craft\web\View;
use yii\base\InvalidConfigException;
use craft\mail\Message;
use craft\mail\Mailer;
use yii\mail\MailEvent;
/**
 * user-registration-mails module
 *
 * @method static Module getInstance()
 */
class Module extends BaseModule
{
    public function init()
    {
        Craft::setAlias('@modules/userregistrationmails', __DIR__);

        // Set the controllerNamespace based on whether this is a console or web request
        if (Craft::$app-&gt;request-&gt;isConsoleRequest) {
            $this-&gt;controllerNamespace = 'modules\\userregistrationmails\\console\\controllers';
        } else {
            $this-&gt;controllerNamespace = 'modules\\userregistrationmails\\controllers';
        }

        parent::init();

        // Defer most setup tasks until Craft is fully initialized
        Craft::$app-&gt;onInit(function() {
            $this-&gt;attachEventHandlers();
            // ...
        });
    }

    private function attachEventHandlers(): void
    {
        Event::on(
            Users::class,
            Users::EVENT_BEFORE_ACTIVATE_USER,
            function (UserEvent $event) {
                $user = $event-&gt;user;
                Craft::$app-&gt;getMailer()
                    -&gt;compose()
                    -&gt;setTo('michiels.arne@gmail.com')
                    -&gt;setSubject('New User')
                    -&gt;setHtmlBody('New User: ' . $user-&gt;firstName . ' ' . $user-&gt;LastName)
                    -&gt;send();
                }
            );
    }
}



</code></pre>
<p>logs:</p>
<pre><code>2023-03-12 08:36:07 [web.INFO] [yii\db\Connection::open] Opening DB connection: mysql:host=db;dbname=db;port=3306 {&quot;memory&quot;:1918440} 
2023-03-12 08:36:07 [web.INFO] [yii\web\Session::open] Session started {&quot;memory&quot;:4463832} 
2023-03-12 08:36:07 [web.INFO] [nystudio107\twigfield\Twigfield::bootstrap] Twigfield module bootstrapped {&quot;memory&quot;:4612280} 
2023-03-12 08:36:07 [web.INFO] [modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::init] save user and send mail module loaded {&quot;memory&quot;:4713800} 
2023-03-12 08:36:07 [web.INFO] [modules\afterprocesswebhookmodule\AfterProcessWebhookModule::init] afterProcessWebhook module loaded {&quot;memory&quot;:4735280} 
2023-03-12 08:36:07 [web.INFO] [homm\hommxmlsitemap\HOMMXMLSitemap::init] HOMM XML Sitemap plugin loaded {&quot;memory&quot;:6438704} 
2023-03-12 08:36:07 [web.INFO] [application] Request context:
$_GET = [
    'p' =&gt; 'admin/actions/users/session-info'
    'site' =&gt; 'default'
    'dontExtendSession' =&gt; '1'
]

$_POST = []

$_COOKIE = [
    'efd04dd08ddd9163864dcf0165762839_username' =&gt; '1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a:2:{i:0;s:41:\&quot;efd04dd08ddd9163864dcf0165762839_username\&quot;;i:1;s:5:\&quot;admin\&quot;;}'
    '__stripe_mid' =&gt; 'e560887f-80e9-4cf2-98ce-53c02e228361d29cfb'
    'CraftSessionId' =&gt; '555e7985a48398f52b3cfa693c8a9273'
    'CRAFT_CSRF_TOKEN' =&gt; '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]

$_FILES = []

$_SERVER = [
    'DEPLOY_NAME' =&gt; 'local'
    'DDEV_WEBSERVER_TYPE' =&gt; 'nginx-fpm'
    'npm_config_cache' =&gt; '/mnt/ddev-global-cache/npm'
    'IS_DDEV_PROJECT' =&gt; 'true'
    'PHP_DEFAULT_VERSION' =&gt; '8.0'
    'HOSTNAME' =&gt; 'scoops-web'
    'MH_SMTP_BIND_ADDR' =&gt; '127.0.0.1:1025'
    'SSH_AUTH_SOCK' =&gt; '/home/.ssh-agent/socket'
    'NODE_EXTRA_CA_CERTS' =&gt; '/mnt/ddev-global-cache/mkcert/rootCA.pem'
    'DOCKER_IP' =&gt; '127.0.0.1'
    'PGPASSWORD' =&gt; 'db'
    'DRUSH_ALLOW_XDEBUG' =&gt; '1'
    'MYSQL_PWD' =&gt; 'db'
    'DDEV_DOCROOT' =&gt; 'web'
    'PWD' =&gt; '/var/www/html'
    'PLATFORMSH_CLI_UPDATES_CHECK' =&gt; '0'
    'DDEV_FILES_DIR' =&gt; ''
    'APACHE_SITE_TEMPLATE' =&gt; '/etc/apache2/apache-site.conf'
    'PHP_INI' =&gt; '/etc/php/8.0/fpm/php.ini'
    'GOARCH' =&gt; 'amd64'
    'DDEV_VERSION' =&gt; 'v1.21.4'
    'TZ' =&gt; ''
    'HTTPS_EXPOSE' =&gt; '443:80,8026:8025'
    'DDEV_PRIMARY_URL' =&gt; 'https://scoops.ddev.site'
    'LINES' =&gt; '30'
    'DDEV_SITENAME' =&gt; 'scoops'
    'HOME' =&gt; '/home/arnemichiels'
    'DRUSH_OPTIONS_URI' =&gt; 'https://scoops.ddev.site'
    'LANG' =&gt; 'C.UTF-8'
    'COLUMNS' =&gt; '120'
    'PGUSER' =&gt; 'db'
    'TERMINUS_CACHE_DIR' =&gt; '/mnt/ddev-global-cache/terminus/cache'
    'DDEV_ROUTER_HTTP_PORT' =&gt; '80'
    'COMPOSER_PROCESS_TIMEOUT' =&gt; '2000'
    'NGINX_SITE_TEMPLATE' =&gt; '/etc/nginx/nginx-site.conf'
    'HTTP_EXPOSE' =&gt; '80:80,8025:8025'
    'DDEV_PHP_VERSION' =&gt; '8.0'
    'DDEV_TLD' =&gt; 'ddev.site'
    'DDEV_HOSTNAME' =&gt; 'scoops.ddev.site'
    'DDEV_PROJECT' =&gt; 'scoops'
    'VIRTUAL_HOST' =&gt; 'scoops.ddev.site'
    'TERM' =&gt; 'xterm'
    'USER' =&gt; 'arnemichiels'
    'MYSQL_HISTFILE' =&gt; '/mnt/ddev-global-cache/mysqlhistory/scoops-web/mysql_history'
    'CAROOT' =&gt; '/mnt/ddev-global-cache/mkcert'
    'SHLVL' =&gt; '0'
    'COMPOSER_ALLOW_SUPERUSER' =&gt; '1'
    'BASH_ENV' =&gt; '/etc/bash.nointeractive.bashrc'
    'DDEV_DATABASE' =&gt; 'mariadb:10.4'
    'PGDATABASE' =&gt; 'db'
    'XHPROF_OUTPUT_DIR' =&gt; '/tmp/xhprof'
    'COMPOSER_CACHE_DIR' =&gt; '/mnt/ddev-global-cache/composer'
    'DDEV_XDEBUG_ENABLED' =&gt; 'false'
    'PGHOST' =&gt; 'db'
    'DDEV_COMPOSER_ROOT' =&gt; '/var/www/html'
    'DOCROOT' =&gt; 'web'
    'TERMINUS_HIDE_UPDATE_MESSAGE' =&gt; '1'
    'PATH' =&gt; '~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/html/vendor/bin:/var/www/html/bin:/var/www/html/vendor/bin'
    'HOST_DOCKER_INTERNAL_IP' =&gt; ''
    'DEBIAN_FRONTEND' =&gt; 'noninteractive'
    'DDEV_PROJECT_TYPE' =&gt; 'craftcms'
    'DDEV_ROUTER_HTTPS_PORT' =&gt; '443'
    'GOOS' =&gt; 'linux'
    'SUPERVISOR_ENABLED' =&gt; '1'
    'SUPERVISOR_SERVER_URL' =&gt; 'unix:///var/run/supervisor.sock'
    'SUPERVISOR_PROCESS_NAME' =&gt; 'php-fpm'
    'SUPERVISOR_GROUP_NAME' =&gt; 'php-fpm'
    'HTTP_COOKIE' =&gt; 'efd04dd08ddd9163864dcf0165762839_username=1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%22efd04dd08ddd9163864dcf0165762839_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; __stripe_mid=e560887f-80e9-4cf2-98ce-53c02e228361d29cfb; CraftSessionId=555e7985a48398f52b3cfa693c8a9273; CRAFT_CSRF_TOKEN=fa2a4edd1e5a0728268bbd16e327a95dbdf8cf57323423b9cb3c7c2f8a9d986ea%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A40%3A%223ePayfcVtp88RIgJ7GkRQnVQFQ9_c2cMGPXHJutn%22%3B%7D'
    'HTTP_ACCEPT_LANGUAGE' =&gt; 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7'
    'HTTP_ACCEPT_ENCODING' =&gt; 'gzip, deflate, br'
    'HTTP_REFERER' =&gt; 'https://scoops.ddev.site/admin/utilities/clear-caches?site=default'
    'HTTP_SEC_FETCH_DEST' =&gt; 'empty'
    'HTTP_SEC_FETCH_MODE' =&gt; 'cors'
    'HTTP_SEC_FETCH_SITE' =&gt; 'same-origin'
    'HTTP_SEC_CH_UA_PLATFORM' =&gt; '\&quot;Windows\&quot;'
    'HTTP_USER_AGENT' =&gt; 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    'HTTP_SEC_CH_UA_MOBILE' =&gt; '?0'
    'HTTP_X_REQUESTED_WITH' =&gt; 'XMLHttpRequest'
    'HTTP_ACCEPT' =&gt; 'application/json, text/javascript, */*; q=0.01'
    'HTTP_SEC_CH_UA' =&gt; '\&quot;Google Chrome\&quot;;v=\&quot;111\&quot;, \&quot;Not(A:Brand\&quot;;v=\&quot;8\&quot;, \&quot;Chromium\&quot;;v=\&quot;111\&quot;'
    'HTTP_X_FORWARDED_PORT' =&gt; '443'
    'HTTP_X_FORWARDED_SSL' =&gt; 'on'
    'HTTP_X_FORWARDED_PROTO' =&gt; 'https'
    'HTTP_X_FORWARDED_FOR' =&gt; '172.18.0.1'
    'HTTP_X_REAL_IP' =&gt; '172.18.0.1'
    'HTTP_CONNECTION' =&gt; 'close'
    'HTTP_HOST' =&gt; 'scoops.ddev.site'
    'HTTPS' =&gt; 'on'
    'REDIRECT_STATUS' =&gt; '200'
    'SERVER_NAME' =&gt; 'scoops.ddev.site'
    'SERVER_PORT' =&gt; '80'
    'SERVER_ADDR' =&gt; '172.18.0.3'
    'REMOTE_PORT' =&gt; '39800'
    'REMOTE_ADDR' =&gt; '172.18.0.6'
    'SERVER_SOFTWARE' =&gt; 'nginx/1.22.1'
    'GATEWAY_INTERFACE' =&gt; 'CGI/1.1'
    'REQUEST_SCHEME' =&gt; 'http'
    'SERVER_PROTOCOL' =&gt; 'HTTP/1.1'
    'DOCUMENT_ROOT' =&gt; '/var/www/html/web'
    'DOCUMENT_URI' =&gt; '/index.php'
    'REQUEST_URI' =&gt; '/index.php?p=admin%2Factions%2Fusers%2Fsession-info&amp;site=default&amp;dontExtendSession=1'
    'CONTENT_LENGTH' =&gt; ''
    'CONTENT_TYPE' =&gt; ''
    'REQUEST_METHOD' =&gt; 'GET'
    'QUERY_STRING' =&gt; 'p=admin%2Factions%2Fusers%2Fsession-info&amp;site=default&amp;dontExtendSession=1'
    'SCRIPT_NAME' =&gt; '/index.php'
    'SCRIPT_FILENAME' =&gt; '/var/www/html/web/index.php'
    'FCGI_ROLE' =&gt; 'RESPONDER'
    'PHP_SELF' =&gt; '/index.php'
    'REQUEST_TIME_FLOAT' =&gt; 1678610167.7182
    'REQUEST_TIME' =&gt; 1678610167
    'CRAFT_APP_ID' =&gt; 'CraftCMS--47a85736-3be8-4c6f-ac80-e3702fe0435c'
    'CRAFT_ENVIRONMENT' =&gt; 'dev'
    'CRAFT_SECURITY_KEY' =&gt; '••••••••••••••••••••••••••••••••'
    'CRAFT_DB_DRIVER' =&gt; 'mysql'
    'CRAFT_DB_SERVER' =&gt; 'db'
    'CRAFT_DB_PORT' =&gt; '3306'
    'CRAFT_DB_DATABASE' =&gt; 'db'
    'CRAFT_DB_USER' =&gt; 'db'
    'CRAFT_DB_PASSWORD' =&gt; '••'
    'CRAFT_DB_SCHEMA' =&gt; ''
    'CRAFT_DB_TABLE_PREFIX' =&gt; ''
    'CP_TRIGGER' =&gt; 'admin'
    'PRIMARY_SITE_URL' =&gt; 'https://scoops.ddev.site'
    'ASSET_BASE_URL' =&gt; 'http://localhost/scoopsardooie/web/uploads'
    'ASSET_BASE_PATH' =&gt; 'uploads'
    'MAILHOG_SMTP_PORT' =&gt; '1025'
    'MAILHOG_SMTP_HOSTNAME' =&gt; '127.0.0.1'
]

$_SESSION = [
    '668ef524e696f2df1a1d0792428f07eb__flash' =&gt; [
        'notice' =&gt; -1
    ]
    'notice' =&gt; 'Gebruiker geregistreerd.'
]  
2023-03-12 08:37:08 [web.INFO] [yii\db\Connection::open] Opening DB connection: mysql:host=db;dbname=db;port=3306 {&quot;memory&quot;:1918440} 
2023-03-12 08:37:08 [web.INFO] [yii\web\Session::open] Session started {&quot;memory&quot;:4463832} 
2023-03-12 08:37:08 [web.INFO] [nystudio107\twigfield\Twigfield::bootstrap] Twigfield module bootstrapped {&quot;memory&quot;:4612280} 
2023-03-12 08:37:08 [web.INFO] [modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::init] save user and send mail module loaded {&quot;memory&quot;:4713800} 
2023-03-12 08:37:08 [web.INFO] [modules\afterprocesswebhookmodule\AfterProcessWebhookModule::init] afterProcessWebhook module loaded {&quot;memory&quot;:4735280} 
2023-03-12 08:37:08 [web.INFO] [homm\hommxmlsitemap\HOMMXMLSitemap::init] HOMM XML Sitemap plugin loaded {&quot;memory&quot;:6438704} 
2023-03-12 08:37:08 [web.INFO] [application] Request context:
$_GET = [
    'p' =&gt; 'admin/actions/users/session-info'
    'site' =&gt; 'default'
    'dontExtendSession' =&gt; '1'
]

$_POST = []

$_COOKIE = [
    'efd04dd08ddd9163864dcf0165762839_username' =&gt; '1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a:2:{i:0;s:41:\&quot;efd04dd08ddd9163864dcf0165762839_username\&quot;;i:1;s:5:\&quot;admin\&quot;;}'
    '__stripe_mid' =&gt; 'e560887f-80e9-4cf2-98ce-53c02e228361d29cfb'
    'CraftSessionId' =&gt; '555e7985a48398f52b3cfa693c8a9273'
    'CRAFT_CSRF_TOKEN' =&gt; '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]

$_FILES = []

$_SERVER = [
    'DEPLOY_NAME' =&gt; 'local'
    'DDEV_WEBSERVER_TYPE' =&gt; 'nginx-fpm'
    'npm_config_cache' =&gt; '/mnt/ddev-global-cache/npm'
    'IS_DDEV_PROJECT' =&gt; 'true'
    'PHP_DEFAULT_VERSION' =&gt; '8.0'
    'HOSTNAME' =&gt; 'scoops-web'
    'MH_SMTP_BIND_ADDR' =&gt; '127.0.0.1:1025'
    'SSH_AUTH_SOCK' =&gt; '/home/.ssh-agent/socket'
    'NODE_EXTRA_CA_CERTS' =&gt; '/mnt/ddev-global-cache/mkcert/rootCA.pem'
    'DOCKER_IP' =&gt; '127.0.0.1'
    'PGPASSWORD' =&gt; 'db'
    'DRUSH_ALLOW_XDEBUG' =&gt; '1'
    'MYSQL_PWD' =&gt; 'db'
    'DDEV_DOCROOT' =&gt; 'web'
    'PWD' =&gt; '/var/www/html'
    'PLATFORMSH_CLI_UPDATES_CHECK' =&gt; '0'
    'DDEV_FILES_DIR' =&gt; ''
    'APACHE_SITE_TEMPLATE' =&gt; '/etc/apache2/apache-site.conf'
    'PHP_INI' =&gt; '/etc/php/8.0/fpm/php.ini'
    'GOARCH' =&gt; 'amd64'
    'DDEV_VERSION' =&gt; 'v1.21.4'
    'TZ' =&gt; ''
    'HTTPS_EXPOSE' =&gt; '443:80,8026:8025'
    'DDEV_PRIMARY_URL' =&gt; 'https://scoops.ddev.site'
    'LINES' =&gt; '30'
    'DDEV_SITENAME' =&gt; 'scoops'
    'HOME' =&gt; '/home/arnemichiels'
    'DRUSH_OPTIONS_URI' =&gt; 'https://scoops.ddev.site'
    'LANG' =&gt; 'C.UTF-8'
    'COLUMNS' =&gt; '120'
    'PGUSER' =&gt; 'db'
    'TERMINUS_CACHE_DIR' =&gt; '/mnt/ddev-global-cache/terminus/cache'
    'DDEV_ROUTER_HTTP_PORT' =&gt; '80'
    'COMPOSER_PROCESS_TIMEOUT' =&gt; '2000'
    'NGINX_SITE_TEMPLATE' =&gt; '/etc/nginx/nginx-site.conf'
    'HTTP_EXPOSE' =&gt; '80:80,8025:8025'
    'DDEV_PHP_VERSION' =&gt; '8.0'
    'DDEV_TLD' =&gt; 'ddev.site'
    'DDEV_HOSTNAME' =&gt; 'scoops.ddev.site'
    'DDEV_PROJECT' =&gt; 'scoops'
    'VIRTUAL_HOST' =&gt; 'scoops.ddev.site'
    'TERM' =&gt; 'xterm'
    'USER' =&gt; 'arnemichiels'
    'MYSQL_HISTFILE' =&gt; '/mnt/ddev-global-cache/mysqlhistory/scoops-web/mysql_history'
    'CAROOT' =&gt; '/mnt/ddev-global-cache/mkcert'
    'SHLVL' =&gt; '0'
    'COMPOSER_ALLOW_SUPERUSER' =&gt; '1'
    'BASH_ENV' =&gt; '/etc/bash.nointeractive.bashrc'
    'DDEV_DATABASE' =&gt; 'mariadb:10.4'
    'PGDATABASE' =&gt; 'db'
    'XHPROF_OUTPUT_DIR' =&gt; '/tmp/xhprof'
    'COMPOSER_CACHE_DIR' =&gt; '/mnt/ddev-global-cache/composer'
    'DDEV_XDEBUG_ENABLED' =&gt; 'false'
    'PGHOST' =&gt; 'db'
    'DDEV_COMPOSER_ROOT' =&gt; '/var/www/html'
    'DOCROOT' =&gt; 'web'
    'TERMINUS_HIDE_UPDATE_MESSAGE' =&gt; '1'
    'PATH' =&gt; '~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/html/vendor/bin:/var/www/html/bin:/var/www/html/vendor/bin'
    'HOST_DOCKER_INTERNAL_IP' =&gt; ''
    'DEBIAN_FRONTEND' =&gt; 'noninteractive'
    'DDEV_PROJECT_TYPE' =&gt; 'craftcms'
    'DDEV_ROUTER_HTTPS_PORT' =&gt; '443'
    'GOOS' =&gt; 'linux'
    'SUPERVISOR_ENABLED' =&gt; '1'
    'SUPERVISOR_SERVER_URL' =&gt; 'unix:///var/run/supervisor.sock'
    'SUPERVISOR_PROCESS_NAME' =&gt; 'php-fpm'
    'SUPERVISOR_GROUP_NAME' =&gt; 'php-fpm'
    'HTTP_COOKIE' =&gt; 'efd04dd08ddd9163864dcf0165762839_username=1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%22efd04dd08ddd9163864dcf0165762839_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; __stripe_mid=e560887f-80e9-4cf2-98ce-53c02e228361d29cfb; CraftSessionId=555e7985a48398f52b3cfa693c8a9273; CRAFT_CSRF_TOKEN=fa2a4edd1e5a0728268bbd16e327a95dbdf8cf57323423b9cb3c7c2f8a9d986ea%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A40%3A%223ePayfcVtp88RIgJ7GkRQnVQFQ9_c2cMGPXHJutn%22%3B%7D'
    'HTTP_ACCEPT_LANGUAGE' =&gt; 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7'
    'HTTP_ACCEPT_ENCODING' =&gt; 'gzip, deflate, br'
    'HTTP_REFERER' =&gt; 'https://scoops.ddev.site/admin/utilities/clear-caches?site=default'
    'HTTP_SEC_FETCH_DEST' =&gt; 'empty'
    'HTTP_SEC_FETCH_MODE' =&gt; 'cors'
    'HTTP_SEC_FETCH_SITE' =&gt; 'same-origin'
    'HTTP_SEC_CH_UA_PLATFORM' =&gt; '\&quot;Windows\&quot;'
    'HTTP_USER_AGENT' =&gt; 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    'HTTP_SEC_CH_UA_MOBILE' =&gt; '?0'
    'HTTP_X_REQUESTED_WITH' =&gt; 'XMLHttpRequest'
    'HTTP_ACCEPT' =&gt; 'application/json, text/javascript, */*; q=0.01'
    'HTTP_SEC_CH_UA' =&gt; '\&quot;Google Chrome\&quot;;v=\&quot;111\&quot;, \&quot;Not(A:Brand\&quot;;v=\&quot;8\&quot;, \&quot;Chromium\&quot;;v=\&quot;111\&quot;'
    'HTTP_X_FORWARDED_PORT' =&gt; '443'
    'HTTP_X_FORWARDED_SSL' =&gt; 'on'
    'HTTP_X_FORWARDED_PROTO' =&gt; 'https'
    'HTTP_X_FORWARDED_FOR' =&gt; '172.18.0.1'
    'HTTP_X_REAL_IP' =&gt; '172.18.0.1'
    'HTTP_CONNECTION' =&gt; 'close'
    'HTTP_HOST' =&gt; 'scoops.ddev.site'
    'HTTPS' =&gt; 'on'
    'REDIRECT_STATUS' =&gt; '200'
    'SERVER_NAME' =&gt; 'scoops.ddev.site'
    'SERVER_PORT' =&gt; '80'
    'SERVER_ADDR' =&gt; '172.18.0.3'
    'REMOTE_PORT' =&gt; '52952'
    'REMOTE_ADDR' =&gt; '172.18.0.6'
    'SERVER_SOFTWARE' =&gt; 'nginx/1.22.1'
    'GATEWAY_INTERFACE' =&gt; 'CGI/1.1'
    'REQUEST_SCHEME' =&gt; 'http'
    'SERVER_PROTOCOL' =&gt; 'HTTP/1.1'
    'DOCUMENT_ROOT' =&gt; '/var/www/html/web'
    'DOCUMENT_URI' =&gt; '/index.php'
    'REQUEST_URI' =&gt; '/index.php?p=admin%2Factions%2Fusers%2Fsession-info&amp;site=default&amp;dontExtendSession=1'
    'CONTENT_LENGTH' =&gt; ''
    'CONTENT_TYPE' =&gt; ''
    'REQUEST_METHOD' =&gt; 'GET'
    'QUERY_STRING' =&gt; 'p=admin%2Factions%2Fusers%2Fsession-info&amp;site=default&amp;dontExtendSession=1'
    'SCRIPT_NAME' =&gt; '/index.php'
    'SCRIPT_FILENAME' =&gt; '/var/www/html/web/index.php'
    'FCGI_ROLE' =&gt; 'RESPONDER'
    'PHP_SELF' =&gt; '/index.php'
    'REQUEST_TIME_FLOAT' =&gt; 1678610228.707
    'REQUEST_TIME' =&gt; 1678610228
    'CRAFT_APP_ID' =&gt; 'CraftCMS--47a85736-3be8-4c6f-ac80-e3702fe0435c'
    'CRAFT_ENVIRONMENT' =&gt; 'dev'
    'CRAFT_SECURITY_KEY' =&gt; '••••••••••••••••••••••••••••••••'
    'CRAFT_DB_DRIVER' =&gt; 'mysql'
    'CRAFT_DB_SERVER' =&gt; 'db'
    'CRAFT_DB_PORT' =&gt; '3306'
    'CRAFT_DB_DATABASE' =&gt; 'db'
    'CRAFT_DB_USER' =&gt; 'db'
    'CRAFT_DB_PASSWORD' =&gt; '••'
    'CRAFT_DB_SCHEMA' =&gt; ''
    'CRAFT_DB_TABLE_PREFIX' =&gt; ''
    'CP_TRIGGER' =&gt; 'admin'
    'PRIMARY_SITE_URL' =&gt; 'https://scoops.ddev.site'
    'ASSET_BASE_URL' =&gt; 'http://localhost/scoopsardooie/web/uploads'
    'ASSET_BASE_PATH' =&gt; 'uploads'
    'MAILHOG_SMTP_PORT' =&gt; '1025'
    'MAILHOG_SMTP_HOSTNAME' =&gt; '127.0.0.1'
]

$_SESSION = [
    '668ef524e696f2df1a1d0792428f07eb__flash' =&gt; [
        'notice' =&gt; -1
    ]
    'notice' =&gt; 'Gebruiker geregistreerd.'
]  

</code></pre>
<p>app.php:</p>
<pre><code>&lt;?php
/**
 * Yii Application Config
 *
 * Edit this file at your own risk!
 *
 * The array returned by this file will get merged with
 * vendor/craftcms/cms/src/config/app.php and app.[web|console].php, when
 * Craft's bootstrap script is defining the configuration for the entire
 * application.
 *
 * You can define custom modules and system components, and even override the
 * built-in system components.
 *
 * If you want to modify the application config for *only* web requests or
 * *only* console requests, create an app.web.php or app.console.php file in
 * your config/ folder, alongside this one.
 */

use craft\helpers\App;
use modules\usermails\Module;
use modules\userregistrationmails\Module as ModuleAlias;

return [
    'id' =&gt; App::env('CRAFT_APP_ID') ?: 'CraftCMS',
    'modules' =&gt; [
        'save-user-and-send-mail-module' =&gt; [
            'class' =&gt; \modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::class,
        ],
        'after-process-webhook-module' =&gt; [
            'class' =&gt; \modules\afterprocesswebhookmodule\AfterProcessWebhookModule::class,
        ],
        'user-registration-mails' =&gt; ModuleAlias::class,
    ],
    'bootstrap' =&gt; ['save-user-and-send-mail-module', 'after-process-webhook-module', 'user-registration-mails'],
];

</code></pre>
<p>composer.json:</p>
<pre><code>    &quot;autoload&quot;: {
        &quot;psr-4&quot;: {
            &quot;modules\\userRegistration\\&quot;: &quot;modules/userRegistration/&quot;,
            &quot;modules\\saveuserandsendmailmodule\\&quot;: &quot;modules/saveuserandsendmailmodule/src/&quot;,
            &quot;modules\\afterprocesswebhookmodule\\&quot;: &quot;modules/afterprocesswebhookmodule/src/&quot;,
            &quot;modules\\usermails\\&quot;: &quot;modules/user-mails/&quot;,
            &quot;modules\\userregistrationmails\\&quot;: &quot;modules/user-registration-mails/&quot;
        }
    },
</code></pre>
<p>modules structure:</p>
<p>modules/
--------user-registration-mails/
-------------------------------module.php</p>
<p>in my logs in the admin the module is not loaded:
<a href="https://i.sstatic.net/3988B.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3988B.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2023-03-06T08:51:22.327Z
What is not working about your code? What behaviour are you seeing?
MoritzLost
CC BY-SA 4.0
2023-03-12T08:41:41.997Z
@MoritzLost it's not sending the e-mail
aren
<modules>
Send mail to admin on new user
# Send mail to admin on new user

(Asked by: username_0 on 2023-03-05)

I'm trying to make a craft module, which sends a mail to the admin whenever a new user registers.
Somehow I'm not able to get this work, anyone knows how to solve this?
The module is not able to send an email.
I used the command line craft commands to setup the structure of this module.
the module is called user registration mails
request->isConsoleRequest) {
            $this->controllerNamespace = 'modules\\userregistrationmails\\console\\controllers';
        } else {
            $this->controllerNamespace = 'modules\\userregistrationmails\\controllers';
        }

        pusername_0t::init();

        // Defer most setup tasks until Craft is fully initialized
        Craft::$app->onInit(function() {
            $this->attachEventHandlers();
            // ...
        });
    }

    private function attachEventHandlers(): void
    {
        Event::on(
            Users::class,
            Users::EVENT_BEFORE_ACTIVATE_USER,
            function (UserEvent $event) {
                $user = $event->user;
                Craft::$app->getMailer()
                    ->compose()
                    ->setTo('michiels.arne@gmail.com')
                    ->setSubject('New User')
                    ->setHtmlBody('New User: ' . $user->firstName . ' ' . $user->LastName)
                    ->send();
                }
            );
    }
}




logs:
2023-03-12 08:36:07 [web.INFO] [yii\db\Connection::open] Opening DB connection: mysql:host=db;dbname=db;port=3306 {"memory":1918440} 
2023-03-12 08:36:07 [web.INFO] [yii\web\Session::open] Session started {"memory":4463832} 
2023-03-12 08:36:07 [web.INFO] [nystudio107\twigfield\Twigfield::bootstrap] Twigfield module bootstrapped {"memory":4612280} 
2023-03-12 08:36:07 [web.INFO] [modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::init] save user and send mail module loaded {"memory":4713800} 
2023-03-12 08:36:07 [web.INFO] [modules\afterprocesswebhookmodule\AfterProcessWebhookModule::init] afterProcessWebhook module loaded {"memory":4735280} 
2023-03-12 08:36:07 [web.INFO] [homm\hommxmlsitemap\HOMMXMLSitemap::init] HOMM XML Sitemap plugin loaded {"memory":6438704} 
2023-03-12 08:36:07 [web.INFO] [application] Request context:
$_GET = [
    'p' => 'admin/actions/users/session-info'
    'site' => 'default'
    'dontExtendSession' => '1'
]

$_POST = []

$_COOKIE = [
    'efd04dd08ddd9163864dcf0165762839_username' => '1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a:2:{i:0;s:41:\"efd04dd08ddd9163864dcf0165762839_username\";i:1;s:5:\"admin\";}'
    '__stripe_mid' => 'e560887f-80e9-4cf2-98ce-53c02e228361d29cfb'
    'CraftSessionId' => '555e7985a48398f52b3cfa693c8a9273'
    'CRAFT_CSRF_TOKEN' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]

$_FILES = []

$_SERVER = [
    'DEPLOY_NAME' => 'local'
    'DDEV_WEBSERVER_TYPE' => 'nginx-fpm'
    'npm_config_cache' => '/mnt/ddev-global-cache/npm'
    'IS_DDEV_PROJECT' => 'true'
    'PHP_DEFAULT_VERSION' => '8.0'
    'HOSTNAME' => 'scoops-web'
    'MH_SMTP_BIND_ADDR' => '127.0.0.1:1025'
    'SSH_AUTH_SOCK' => '/home/.ssh-agent/socket'
    'NODE_EXTRA_CA_CERTS' => '/mnt/ddev-global-cache/mkcert/rootCA.pem'
    'DOCKER_IP' => '127.0.0.1'
    'PGPASSWORD' => 'db'
    'DRUSH_ALLOW_XDEBUG' => '1'
    'MYSQL_PWD' => 'db'
    'DDEV_DOCROOT' => 'web'
    'PWD' => '/var/www/html'
    'PLATFORMSH_CLI_UPDATES_CHECK' => '0'
    'DDEV_FILES_DIR' => ''
    'APACHE_SITE_TEMPLATE' => '/etc/apache2/apache-site.conf'
    'PHP_INI' => '/etc/php/8.0/fpm/php.ini'
    'GOARCH' => 'amd64'
    'DDEV_VERSION' => 'v1.21.4'
    'TZ' => ''
    'HTTPS_EXPOSE' => '443:80,8026:8025'
    'DDEV_PRIMARY_URL' => 'https://scoops.ddev.site'
    'LINES' => '30'
    'DDEV_SITENAME' => 'scoops'
    'HOME' => '/home/arnemichiels'
    'DRUSH_OPTIONS_URI' => 'https://scoops.ddev.site'
    'LANG' => 'C.UTF-8'
    'COLUMNS' => '120'
    'PGUSER' => 'db'
    'TERMINUS_CACHE_DIR' => '/mnt/ddev-global-cache/terminus/cache'
    'DDEV_ROUTER_HTTP_PORT' => '80'
    'COMPOSER_PROCESS_TIMEOUT' => '2000'
    'NGINX_SITE_TEMPLATE' => '/etc/nginx/nginx-site.conf'
    'HTTP_EXPOSE' => '80:80,8025:8025'
    'DDEV_PHP_VERSION' => '8.0'
    'DDEV_TLD' => 'ddev.site'
    'DDEV_HOSTNAME' => 'scoops.ddev.site'
    'DDEV_PROJECT' => 'scoops'
    'VIRTUAL_HOST' => 'scoops.ddev.site'
    'TERM' => 'xterm'
    'USER' => 'arnemichiels'
    'MYSQL_HISTFILE' => '/mnt/ddev-global-cache/mysqlhistory/scoops-web/mysql_history'
    'CAROOT' => '/mnt/ddev-global-cache/mkcert'
    'SHLVL' => '0'
    'COMPOSER_ALLOW_SUPERUSER' => '1'
    'BASH_ENV' => '/etc/bash.nointeractive.bashrc'
    'DDEV_DATABASE' => 'mariadb:10.4'
    'PGDATABASE' => 'db'
    'XHPROF_OUTPUT_DIR' => '/tmp/xhprof'
    'COMPOSER_CACHE_DIR' => '/mnt/ddev-global-cache/composer'
    'DDEV_XDEBUG_ENABLED' => 'false'
    'PGHOST' => 'db'
    'DDEV_COMPOSER_ROOT' => '/var/www/html'
    'DOCROOT' => 'web'
    'TERMINUS_HIDE_UPDATE_MESSAGE' => '1'
    'PATH' => '~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/html/vendor/bin:/var/www/html/bin:/var/www/html/vendor/bin'
    'HOST_DOCKER_INTERNAL_IP' => ''
    'DEBIAN_FRONTEND' => 'noninteractive'
    'DDEV_PROJECT_TYPE' => 'craftcms'
    'DDEV_ROUTER_HTTPS_PORT' => '443'
    'GOOS' => 'linux'
    'SUPERVISOR_ENABLED' => '1'
    'SUPERVISOR_SERVER_URL' => 'unix:///var/run/supervisor.sock'
    'SUPERVISOR_PROCESS_NAME' => 'php-fpm'
    'SUPERVISOR_GROUP_NAME' => 'php-fpm'
    'HTTP_COOKIE' => 'efd04dd08ddd9163864dcf0165762839_username=1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%22efd04dd08ddd9163864dcf0165762839_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; __stripe_mid=e560887f-80e9-4cf2-98ce-53c02e228361d29cfb; CraftSessionId=555e7985a48398f52b3cfa693c8a9273; CRAFT_CSRF_TOKEN=fa2a4edd1e5a0728268bbd16e327a95dbdf8cf57323423b9cb3c7c2f8a9d986ea%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A40%3A%223ePayfcVtp88RIgJ7GkRQnVQFQ9_c2cMGPXHJutn%22%3B%7D'
    'HTTP_ACCEPT_LANGUAGE' => 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7'
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
    'HTTP_REFERER' => 'https://scoops.ddev.site/admin/utilities/clear-caches?site=default'
    'HTTP_SEC_FETCH_DEST' => 'empty'
    'HTTP_SEC_FETCH_MODE' => 'cors'
    'HTTP_SEC_FETCH_SITE' => 'same-origin'
    'HTTP_SEC_CH_UA_PLATFORM' => '\"Windows\"'
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    'HTTP_SEC_CH_UA_MOBILE' => '?0'
    'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
    'HTTP_ACCEPT' => 'application/json, text/javascript, */*; q=0.01'
    'HTTP_SEC_CH_UA' => '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"'
    'HTTP_X_FORWARDED_PORT' => '443'
    'HTTP_X_FORWARDED_SSL' => 'on'
    'HTTP_X_FORWARDED_PROTO' => 'https'
    'HTTP_X_FORWARDED_FOR' => '172.18.0.1'
    'HTTP_X_REAL_IP' => '172.18.0.1'
    'HTTP_CONNECTION' => 'close'
    'HTTP_HOST' => 'scoops.ddev.site'
    'HTTPS' => 'on'
    'REDIRECT_STATUS' => '200'
    'SERVER_NAME' => 'scoops.ddev.site'
    'SERVER_PORT' => '80'
    'SERVER_ADDR' => '172.18.0.3'
    'REMOTE_PORT' => '39800'
    'REMOTE_ADDR' => '172.18.0.6'
    'SERVER_SOFTWARE' => 'nginx/1.22.1'
    'GATEWAY_INTERFACE' => 'CGI/1.1'
    'REQUEST_SCHEME' => 'http'
    'SERVER_PROTOCOL' => 'HTTP/1.1'
    'DOCUMENT_ROOT' => '/var/www/html/web'
    'DOCUMENT_URI' => '/index.php'
    'REQUEST_URI' => '/index.php?p=admin%2Factions%2Fusers%2Fsession-info&site=default&dontExtendSession=1'
    'CONTENT_LENGTH' => ''
    'CONTENT_TYPE' => ''
    'REQUEST_METHOD' => 'GET'
    'QUERY_STRING' => 'p=admin%2Factions%2Fusers%2Fsession-info&site=default&dontExtendSession=1'
    'SCRIPT_NAME' => '/index.php'
    'SCRIPT_FILENAME' => '/var/www/html/web/index.php'
    'FCGI_ROLE' => 'RESPONDER'
    'PHP_SELF' => '/index.php'
    'REQUEST_TIME_FLOAT' => 1678610167.7182
    'REQUEST_TIME' => 1678610167
    'CRAFT_APP_ID' => 'CraftCMS--47a85736-3be8-4c6f-ac80-e3702fe0435c'
    'CRAFT_ENVIRONMENT' => 'dev'
    'CRAFT_SECURITY_KEY' => '••••••••••••••••••••••••••••••••'
    'CRAFT_DB_DRIVER' => 'mysql'
    'CRAFT_DB_SERVER' => 'db'
    'CRAFT_DB_PORT' => '3306'
    'CRAFT_DB_DATABASE' => 'db'
    'CRAFT_DB_USER' => 'db'
    'CRAFT_DB_PASSWORD' => '••'
    'CRAFT_DB_SCHEMA' => ''
    'CRAFT_DB_TABLE_PREFIX' => ''
    'CP_TRIGGER' => 'admin'
    'PRIMARY_SITE_URL' => 'https://scoops.ddev.site'
    'ASSET_BASE_URL' => 'http://localhost/scoopsardooie/web/uploads'
    'ASSET_BASE_PATH' => 'uploads'
    'MAILHOG_SMTP_PORT' => '1025'
    'MAILHOG_SMTP_HOSTNAME' => '127.0.0.1'
]

$_SESSION = [
    '668ef524e696f2df1a1d0792428f07eb__flash' => [
        'notice' => -1
    ]
    'notice' => 'Gebruiker geregistreerd.'
]  
2023-03-12 08:37:08 [web.INFO] [yii\db\Connection::open] Opening DB connection: mysql:host=db;dbname=db;port=3306 {"memory":1918440} 
2023-03-12 08:37:08 [web.INFO] [yii\web\Session::open] Session started {"memory":4463832} 
2023-03-12 08:37:08 [web.INFO] [nystudio107\twigfield\Twigfield::bootstrap] Twigfield module bootstrapped {"memory":4612280} 
2023-03-12 08:37:08 [web.INFO] [modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::init] save user and send mail module loaded {"memory":4713800} 
2023-03-12 08:37:08 [web.INFO] [modules\afterprocesswebhookmodule\AfterProcessWebhookModule::init] afterProcessWebhook module loaded {"memory":4735280} 
2023-03-12 08:37:08 [web.INFO] [homm\hommxmlsitemap\HOMMXMLSitemap::init] HOMM XML Sitemap plugin loaded {"memory":6438704} 
2023-03-12 08:37:08 [web.INFO] [application] Request context:
$_GET = [
    'p' => 'admin/actions/users/session-info'
    'site' => 'default'
    'dontExtendSession' => '1'
]

$_POST = []

$_COOKIE = [
    'efd04dd08ddd9163864dcf0165762839_username' => '1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a:2:{i:0;s:41:\"efd04dd08ddd9163864dcf0165762839_username\";i:1;s:5:\"admin\";}'
    '__stripe_mid' => 'e560887f-80e9-4cf2-98ce-53c02e228361d29cfb'
    'CraftSessionId' => '555e7985a48398f52b3cfa693c8a9273'
    'CRAFT_CSRF_TOKEN' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]

$_FILES = []

$_SERVER = [
    'DEPLOY_NAME' => 'local'
    'DDEV_WEBSERVER_TYPE' => 'nginx-fpm'
    'npm_config_cache' => '/mnt/ddev-global-cache/npm'
    'IS_DDEV_PROJECT' => 'true'
    'PHP_DEFAULT_VERSION' => '8.0'
    'HOSTNAME' => 'scoops-web'
    'MH_SMTP_BIND_ADDR' => '127.0.0.1:1025'
    'SSH_AUTH_SOCK' => '/home/.ssh-agent/socket'
    'NODE_EXTRA_CA_CERTS' => '/mnt/ddev-global-cache/mkcert/rootCA.pem'
    'DOCKER_IP' => '127.0.0.1'
    'PGPASSWORD' => 'db'
    'DRUSH_ALLOW_XDEBUG' => '1'
    'MYSQL_PWD' => 'db'
    'DDEV_DOCROOT' => 'web'
    'PWD' => '/var/www/html'
    'PLATFORMSH_CLI_UPDATES_CHECK' => '0'
    'DDEV_FILES_DIR' => ''
    'APACHE_SITE_TEMPLATE' => '/etc/apache2/apache-site.conf'
    'PHP_INI' => '/etc/php/8.0/fpm/php.ini'
    'GOARCH' => 'amd64'
    'DDEV_VERSION' => 'v1.21.4'
    'TZ' => ''
    'HTTPS_EXPOSE' => '443:80,8026:8025'
    'DDEV_PRIMARY_URL' => 'https://scoops.ddev.site'
    'LINES' => '30'
    'DDEV_SITENAME' => 'scoops'
    'HOME' => '/home/arnemichiels'
    'DRUSH_OPTIONS_URI' => 'https://scoops.ddev.site'
    'LANG' => 'C.UTF-8'
    'COLUMNS' => '120'
    'PGUSER' => 'db'
    'TERMINUS_CACHE_DIR' => '/mnt/ddev-global-cache/terminus/cache'
    'DDEV_ROUTER_HTTP_PORT' => '80'
    'COMPOSER_PROCESS_TIMEOUT' => '2000'
    'NGINX_SITE_TEMPLATE' => '/etc/nginx/nginx-site.conf'
    'HTTP_EXPOSE' => '80:80,8025:8025'
    'DDEV_PHP_VERSION' => '8.0'
    'DDEV_TLD' => 'ddev.site'
    'DDEV_HOSTNAME' => 'scoops.ddev.site'
    'DDEV_PROJECT' => 'scoops'
    'VIRTUAL_HOST' => 'scoops.ddev.site'
    'TERM' => 'xterm'
    'USER' => 'arnemichiels'
    'MYSQL_HISTFILE' => '/mnt/ddev-global-cache/mysqlhistory/scoops-web/mysql_history'
    'CAROOT' => '/mnt/ddev-global-cache/mkcert'
    'SHLVL' => '0'
    'COMPOSER_ALLOW_SUPERUSER' => '1'
    'BASH_ENV' => '/etc/bash.nointeractive.bashrc'
    'DDEV_DATABASE' => 'mariadb:10.4'
    'PGDATABASE' => 'db'
    'XHPROF_OUTPUT_DIR' => '/tmp/xhprof'
    'COMPOSER_CACHE_DIR' => '/mnt/ddev-global-cache/composer'
    'DDEV_XDEBUG_ENABLED' => 'false'
    'PGHOST' => 'db'
    'DDEV_COMPOSER_ROOT' => '/var/www/html'
    'DOCROOT' => 'web'
    'TERMINUS_HIDE_UPDATE_MESSAGE' => '1'
    'PATH' => '~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/html/vendor/bin:/var/www/html/bin:/var/www/html/vendor/bin'
    'HOST_DOCKER_INTERNAL_IP' => ''
    'DEBIAN_FRONTEND' => 'noninteractive'
    'DDEV_PROJECT_TYPE' => 'craftcms'
    'DDEV_ROUTER_HTTPS_PORT' => '443'
    'GOOS' => 'linux'
    'SUPERVISOR_ENABLED' => '1'
    'SUPERVISOR_SERVER_URL' => 'unix:///var/run/supervisor.sock'
    'SUPERVISOR_PROCESS_NAME' => 'php-fpm'
    'SUPERVISOR_GROUP_NAME' => 'php-fpm'
    'HTTP_COOKIE' => 'efd04dd08ddd9163864dcf0165762839_username=1d8ae463c52d3a45522adc09626ea8dd6ae8b81367efb6feb5e76b8381d0cef2a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%22efd04dd08ddd9163864dcf0165762839_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; __stripe_mid=e560887f-80e9-4cf2-98ce-53c02e228361d29cfb; CraftSessionId=555e7985a48398f52b3cfa693c8a9273; CRAFT_CSRF_TOKEN=fa2a4edd1e5a0728268bbd16e327a95dbdf8cf57323423b9cb3c7c2f8a9d986ea%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A40%3A%223ePayfcVtp88RIgJ7GkRQnVQFQ9_c2cMGPXHJutn%22%3B%7D'
    'HTTP_ACCEPT_LANGUAGE' => 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7'
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
    'HTTP_REFERER' => 'https://scoops.ddev.site/admin/utilities/clear-caches?site=default'
    'HTTP_SEC_FETCH_DEST' => 'empty'
    'HTTP_SEC_FETCH_MODE' => 'cors'
    'HTTP_SEC_FETCH_SITE' => 'same-origin'
    'HTTP_SEC_CH_UA_PLATFORM' => '\"Windows\"'
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    'HTTP_SEC_CH_UA_MOBILE' => '?0'
    'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
    'HTTP_ACCEPT' => 'application/json, text/javascript, */*; q=0.01'
    'HTTP_SEC_CH_UA' => '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"'
    'HTTP_X_FORWARDED_PORT' => '443'
    'HTTP_X_FORWARDED_SSL' => 'on'
    'HTTP_X_FORWARDED_PROTO' => 'https'
    'HTTP_X_FORWARDED_FOR' => '172.18.0.1'
    'HTTP_X_REAL_IP' => '172.18.0.1'
    'HTTP_CONNECTION' => 'close'
    'HTTP_HOST' => 'scoops.ddev.site'
    'HTTPS' => 'on'
    'REDIRECT_STATUS' => '200'
    'SERVER_NAME' => 'scoops.ddev.site'
    'SERVER_PORT' => '80'
    'SERVER_ADDR' => '172.18.0.3'
    'REMOTE_PORT' => '52952'
    'REMOTE_ADDR' => '172.18.0.6'
    'SERVER_SOFTWARE' => 'nginx/1.22.1'
    'GATEWAY_INTERFACE' => 'CGI/1.1'
    'REQUEST_SCHEME' => 'http'
    'SERVER_PROTOCOL' => 'HTTP/1.1'
    'DOCUMENT_ROOT' => '/var/www/html/web'
    'DOCUMENT_URI' => '/index.php'
    'REQUEST_URI' => '/index.php?p=admin%2Factions%2Fusers%2Fsession-info&site=default&dontExtendSession=1'
    'CONTENT_LENGTH' => ''
    'CONTENT_TYPE' => ''
    'REQUEST_METHOD' => 'GET'
    'QUERY_STRING' => 'p=admin%2Factions%2Fusers%2Fsession-info&site=default&dontExtendSession=1'
    'SCRIPT_NAME' => '/index.php'
    'SCRIPT_FILENAME' => '/var/www/html/web/index.php'
    'FCGI_ROLE' => 'RESPONDER'
    'PHP_SELF' => '/index.php'
    'REQUEST_TIME_FLOAT' => 1678610228.707
    'REQUEST_TIME' => 1678610228
    'CRAFT_APP_ID' => 'CraftCMS--47a85736-3be8-4c6f-ac80-e3702fe0435c'
    'CRAFT_ENVIRONMENT' => 'dev'
    'CRAFT_SECURITY_KEY' => '••••••••••••••••••••••••••••••••'
    'CRAFT_DB_DRIVER' => 'mysql'
    'CRAFT_DB_SERVER' => 'db'
    'CRAFT_DB_PORT' => '3306'
    'CRAFT_DB_DATABASE' => 'db'
    'CRAFT_DB_USER' => 'db'
    'CRAFT_DB_PASSWORD' => '••'
    'CRAFT_DB_SCHEMA' => ''
    'CRAFT_DB_TABLE_PREFIX' => ''
    'CP_TRIGGER' => 'admin'
    'PRIMARY_SITE_URL' => 'https://scoops.ddev.site'
    'ASSET_BASE_URL' => 'http://localhost/scoopsardooie/web/uploads'
    'ASSET_BASE_PATH' => 'uploads'
    'MAILHOG_SMTP_PORT' => '1025'
    'MAILHOG_SMTP_HOSTNAME' => '127.0.0.1'
]

$_SESSION = [
    '668ef524e696f2df1a1d0792428f07eb__flash' => [
        'notice' => -1
    ]
    'notice' => 'Gebruiker geregistreerd.'
]  


app.php:
 App::env('CRAFT_APP_ID') ?: 'CraftCMS',
    'modules' => [
        'save-user-and-send-mail-module' => [
            'class' => \modules\saveuserandsendmailmodule\SaveUserAndSendMailModule::class,
        ],
        'after-process-webhook-module' => [
            'class' => \modules\afterprocesswebhookmodule\AfterProcessWebhookModule::class,
        ],
        'user-registration-mails' => ModuleAlias::class,
    ],
    'bootstrap' => ['save-user-and-send-mail-module', 'after-process-webhook-module', 'user-registration-mails'],
];


composer.json:
    "autoload": {
        "psr-4": {
            "modules\\userRegistration\\": "modules/userRegistration/",
            "modules\\saveuserandsendmailmodule\\": "modules/saveuserandsendmailmodule/src/",
            "modules\\afterprocesswebhookmodule\\": "modules/afterprocesswebhookmodule/src/",
            "modules\\usermails\\": "modules/user-mails/",
            "modules\\userregistrationmails\\": "modules/user-registration-mails/"
        }
    },

modules structure:
modules/
--------user-registration-mails/
-------------------------------module.php
in my logs in the admin the module is not loaded:

**Tags:** modules

> **Comments:**
> **username_1**: What is not working about your code? What behaviour are you seeing?  
> **username_0**: @username_1 it's not sending the e-mail  

---

## 2 answers

### Answer by username_0 on 2023-03-19. Score: 1 | Accepted answer

I fixed it by putting the Event::on inside the init


---

### Answer by username_2 on 2023-03-06. Score: 1

You haven’t said what is not working, which makes it difficult to answer your question. Please ensure that your email settings are correctly configured and working. Also note that you’ve chosen to use the EVENT_BEFORE_ACTIVATE_USER event, which is triggered before a user is activated.
The event handler should work as follows:
        Event::on(
            Users::class,
            Users::EVENT_BEFORE_ACTIVATE_USER,
            function (UserEvent $event) {
                $user = $event->user;
                Craft::$app->getMailer()
                    ->compose()
                    ->setTo('test@test.com')
                    ->setSubject('New User')
                    ->setHtmlBody('New User: ' . $user->firstName . ' ' . $user->LastName)
                    ->send();
            }
        );

> **Comments:**
> **username_3**: To expand on Ben's answer - there's a test email button in the email configuration settings. Try that to make sure email is working at all, or if it's just emails being sent from this module  
> **username_0**: Hi guys thanks for responding, my emails are working since I'm using some contact forms which are working fine, it is indeed the emails are not sent from this module  
> **username_2**: @username_0 Can you check the log files in `/storage/logs` for errors?  
> **username_0**: @BenCroker hey I added the logs to my post  
> **username_0**: @BenCroker it looks like it's not calling the module  
> **username_2**: Are you bootstrapping the module in `app.php`?  
> **username_0**: @BenCroker yes it is in bootstrap  
> **username_4**: Did you do `composer dump-autoload`? Also can you try `var_dump('test')` after `pusername_0t::init()` in your module, will it dump 'test' on the site? If not then your module is not active.  
> **username_0**: @username_4 yes i did a dump auto load and var dump is showing on the site  
> **username_0**: Guys thanks for your effort everyone I got the module working by putting the event in the init instead of in the attacheventhandlers  

---

