1

I have several sites running under one Craft install. Two of them are for our internal use, and one is public-facing. On the public-facing site, I need to provide a reset password function. When the email is generated to the user, it looks like this:

{Name of primary site} info@primarysite.com Wed 2/24/2021 1:13 PM Hey Ben, To reset your {name of primary site} password, click on this link: https://public-facing-site.edu/admin/set-password?code=nwKE16ULcdBfj30IDhfZWz4IOjlhkkjlf8hi75fi87aw5f8o75of757i8

Is it possible to customize this email to reflect the site which the user has accessed? Note that the domain name part of the password reset URL is the correct public-facing one. I see the area Utilities > System Messages where I can customize this, but the email still includes reference to the primary site.

2

You can do this by overriding fromName and fromEmail in the mailer component config based on your site handle (or language).

You would do this in your config/app.php like so:

'components' => [
    'mailer' => function() {
        // Fetch the site the user is on
        $currentSiteLanguage = Craft::$app->getSites()->currentSite->handle;

        // Fetch the stored email settings
        $settings = craft\helpers\App::mailSettings();

        // Define the name and email address based on language. Change `public` to match your own site handle
        $fromName = $currentSiteLanguage == 'public' ? 'From your public site' : 'Default from name';

        $fromEmail = $currentSiteLanguage == 'public' ? 'email@public.site' : 'default@email.address';

        // Apply the name to existing settings
        $settings->fromName = $fromName;

        // Apply the name to existing settings
        $settings->fromEmail = $fromEmail;

        // Create a Mailer component config with these settings
        $config = craft\helpers\App::mailerConfig($settings);

        // Instantiate and return it
        return Craft::createObject($config);
    },
],

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.