1

How can I change the domain in the generated {{ link }} in a system email, other than the primary domain?

I have a multi domain setup in craft3, and it works fine everywhere, except ... for the system messages.

For instance, when a user registers using a front-end entry form on a domain other than my primary domain, they receive the correct email, generated by the following template (Admin -> Email Settings -> System Messages):

Hey {{user.friendlyName}},

Thanks for creating an account with {{siteName}}! To activate your account, click the following link:

{{link}}

If you were not expecting this email, just ignore it.


The {{ siteName }} is rendered correctly in the email, but the {{ link }} still points to the primary domain, something like this: https://myprimaryandhtusthewrongdomain/actions/users/set-password?code=nicecode

I use the mailgun adapter to send the mails btw

  • Just some more background info. My setup is as follows: 1. on my server, three domains point to my /craft3/web/ folder as the document root. 2. I filled in the base url setting for all domains inside the control panel. 3. One of them is the primary domain. 4. It is however with domains other than the primary domain that system messages {{ link }} back to the primary domain, where they shouldn’t – monchito Jun 23 '18 at 14:22
1

This is currently expected behavior due to this bit of code, which explicitly passes in the primary site ID when generating those link URLs for a user:

https://github.com/craftcms/cms/blob/develop/src/services/Users.php#L1079-L1081

The reasoning is that even on a multi-site setup, users are all "global" (i.e. not defined per site).

If you feel this is a bug or produces undesired behavior, feel free to create an issue where it can be further discussed.

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.