Answers.Body: <p>Figured it out by debugging <code>getSiteUrl</code> in <code>UrlHelper</code>.</p>
  
  <p>Setting siteUrl like <code>'siteUrl' =&gt; strtolower((isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'])</code> is fine for browser requests, but <code>$_SERVER['SERVER_NAME']</code> isn't available when running a console command.</p>
  
  <p>The scheme is set correctly and since we have <code>addTrailingSlashesToUrls</code> set to <code>false</code>, the result became <code>http:/</code>.</p>
  
  <p>Fixed for now by hard-coding siteUrl in our general.php for each environment.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-04T08:02:31.903Z
Answers.LastActivityDate: 2017-09-04T08:02:31.903Z
Answers.UserDisplayName: Jan Henckens
Body: <p>Running into a weird issue with the site build I'm working currently: </p>
  
  <p>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 <code>craft()-&gt;users-&gt;sendActivationEmail($user)</code>).</p>
  
  <p>The email gets sent out but the activation <code>{{link}}</code> is missing the host part of the URL. Instead we're seeing links like this: <code>http:/actions/users/setpassword?code=bo2EDjfC7ebsrEpsx5T%7EyJ2Q6TRR0bI6&amp;id=912b5712-89f6-4dbc-9337-dec15b518536</code>.</p>
  
  <p>Add the host in between and the link works perfectly. I've tried setting a <code>{{ siteUrl }}</code> specifically the locale I'm in but that doesn't do the trick either.</p>
  
  <p>When I go to the new user in the back-end and copy the activation URL there, that one is correct.</p>
  
  <p>Any pointers as to what might be causing this? Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is the <code>craft/config/general.php</code> we're using:</p>
  
  <pre><code>&lt;?php
  
  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');
              break;
  
          case '/data/sites/web/'.PROJECTCODE.'/subsites/'.PROJECTCODE.'.staging.be/public';
              define('ENV', 'staging');
              break;
  
          default:
              define('ENV', 'local');
              break;
      }
  }
  
  $settings = [
      'subscriptionPrice' =&gt; 275,
      'subscriptionPeriod' =&gt; 'P1Y',
      'invoicePrefix' =&gt; 'ECF2017',
      'autoLoginAfterAccountActivation' =&gt; true,
      'useEmailAsUsername' =&gt; true,
      'setPasswordPath' =&gt; '_members/_reset',
      'logoutPath'=&gt; 'e-learning',
      'defaultCpLanguage' =&gt; 'en_be',
      'defaultWeekStartDay' =&gt; 1,
      'logoutPath' =&gt; 'logout',
      'enableCsrfProtection' =&gt; true,
      'omitScriptNameInUrls' =&gt; true,
      'postCpLoginRedirect' =&gt; 'entries',
      'addTrailingSlashesToUrls' =&gt; false,
      'defaultSearchTermOptions' =&gt; array(
          'subLeft' =&gt; true,
          'subRight' =&gt; true,
      ),
      'environmentVariables' =&gt; [
          'basePath' =&gt; getcwd(),
          'baseUrl' =&gt; strtolower((isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']),
      ],
      'siteUrl' =&gt; strtolower((isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']),
  ];
  
  switch (ENV) {
      case 'live':
          $settings['devMode'] = false;
          $settings['cache'] = true;
          break;
  
      case 'staging':
          $settings['devMode'] = true;
          $settings['cache'] = false;
          break;
  
      default:
          $settings['devMode'] = true;
          $settings['cache'] = false;
          break;
  }
  
  return $settings;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-29T18:23:06.783Z
Comments.Text: 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](https://craftcms.com/docs/config-settings#siteUrl) config setting. Are you sure that's set correctly for your current environment?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-30T07:03:16.437Z
Comments.Text: 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.
Comments.UserDisplayName: Jan Henckens
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-30T21:54:48.163Z
Comments.Text: Weird... maybe some funky `.htaccess` rewrite rule interfering with that request?  Can you edit the question to share your `craft/config/general.php` file?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-31T13:10:45.600Z
Comments.Text: 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.
Comments.UserDisplayName: Jan Henckens
Tags: <users><emails><activation>
Title: Activiation URL empty
ThreadText: # Activiation URL empty
  
  (Asked by: username_0 on 2017-08-29)
  
  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!
  
  **UPDATE**
  
  This is the `craft/config/general.php` we're using:
  
  ```
  <?php
  
  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');
              break;
  
          case '/data/sites/web/'.PROJECTCODE.'/subsites/'.PROJECTCODE.'.staging.be/public';
              define('ENV', 'staging');
              break;
  
          default:
              define('ENV', 'local');
              break;
      }
  }
  
  $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;
          break;
  
      case 'staging':
          $settings['devMode'] = true;
          $settings['cache'] = false;
          break;
  
      default:
          $settings['devMode'] = true;
          $settings['cache'] = false;
          break;
  }
  
  return $settings;
  
  ```
  
  **Tags:** users, emails, activation
  
  > **Comments:**
  > **username_1**: 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](https://craftcms.com/docs/config-settings#siteUrl) config setting. Are you sure that's set correctly for your current environment?  
  > **username_0**: 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.  
  > **username_1**: Weird... maybe some funky `.htaccess` rewrite rule interfering with that request?  Can you edit the question to share your `craft/config/general.php` file?  
  > **username_0**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-09-04. Score: 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.
  
  
  ---
  
  