Running into a weird issue with the site build I'm working currently:

We're creating users based on email addresses coming from an event platform API and are sending activation emails to those users (from our plugin, using craft()->users->sendActivationEmail($user)).

The email gets sent out but the activation {{link}} is missing the host part of the URL. Instead we're seeing links like this: http:/actions/users/setpassword?code=bo2EDjfC7ebsrEpsx5T%7EyJ2Q6TRR0bI6&id=912b5712-89f6-4dbc-9337-dec15b518536.

Add the host in between and the link works perfectly. I've tried setting a {{ siteUrl }} specifically the locale I'm in but that doesn't do the trick either.

When I go to the new user in the back-end and copy the activation URL there, that one is correct.

Any pointers as to what might be causing this? Thanks!


This is the craft/config/general.php we're using:


if (!defined('PROJECTCODE')) {
    define('PROJECTCODE', strtolower('seapla'));

if (!defined('ENV')) {
    switch (strtolower($_SERVER['DOCUMENT_ROOT'])) {
        case '/data/sites/web/'.PROJECTCODE.'/subsites/'.PROJECTCODE.'.live.be/public';
            define('ENV', 'live');

        case '/data/sites/web/'.PROJECTCODE.'/subsites/'.PROJECTCODE.'.staging.be/public';
            define('ENV', 'staging');

            define('ENV', 'local');

$settings = [
    'subscriptionPrice' => 275,
    'subscriptionPeriod' => 'P1Y',
    'invoicePrefix' => 'ECF2017',
    'autoLoginAfterAccountActivation' => true,
    'useEmailAsUsername' => true,
    'setPasswordPath' => '_members/_reset',
    'logoutPath'=> 'e-learning',
    'defaultCpLanguage' => 'en_be',
    'defaultWeekStartDay' => 1,
    'logoutPath' => 'logout',
    'enableCsrfProtection' => true,
    'omitScriptNameInUrls' => true,
    'postCpLoginRedirect' => 'entries',
    'addTrailingSlashesToUrls' => false,
    'defaultSearchTermOptions' => array(
        'subLeft' => true,
        'subRight' => true,
    'environmentVariables' => [
        'basePath' => getcwd(),
        'baseUrl' => strtolower((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']),
    'siteUrl' => strtolower((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']),

switch (ENV) {
    case 'live':
        $settings['devMode'] = false;
        $settings['cache'] = true;

    case 'staging':
        $settings['devMode'] = true;
        $settings['cache'] = false;

        $settings['devMode'] = true;
        $settings['cache'] = false;

return $settings;
  • Do the user accounts have CP access or just front-end site access? Regardless, the host name portion of the URL should be getting pulled from the siteUrl config setting. Are you sure that's set correctly for your current environment?
    – Brad Bell
    Aug 29, 2017 at 18:23
  • Yes, siteUrl is set and working. When I print it in my templates, the correct url is used. The user in question is created as pending, with no groups or permissions, so they shouldn't have access to the CP. Aug 30, 2017 at 7:03
  • Weird... maybe some funky .htaccess rewrite rule interfering with that request? Can you edit the question to share your craft/config/general.php file?
    – Brad Bell
    Aug 30, 2017 at 21:54
  • The url is empty in the email body so I don't think htaccess could have anything to do with it. Updating the question with the general.php we're using. Aug 31, 2017 at 13:10

1 Answer 1


Figured it out by debugging getSiteUrl in UrlHelper.

Setting siteUrl like 'siteUrl' => strtolower((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']) is fine for browser requests, but $_SERVER['SERVER_NAME'] isn't available when running a console command.

The scheme is set correctly and since we have addTrailingSlashesToUrls set to false, the result became http:/.

Fixed for now by hard-coding siteUrl in our general.php for each environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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