The unsubscribe link in my Simplenews footers is correct, other than having an http://default instead of the correct URL at the start. Strangely, this isn't like this in the test messages from Simplenews, which also do not seem to be using any of the theme templates. I am using the token [simplenews-subscriber:unsubscribe-url] as per the Simplenews documentation.

This seems to be a problem with the URL being correctly replaced in the token. Can you advise on the best way to fix this, in either my setup, in Domain Access, or in Simplenews?

Comments

agentrickard’s picture

How are these files being generated? Through a normal Drupal page request or via the command line (e.g. during a cron run)?

This typically happens when using drush or other CLI tools that don't pass a $_SERVER['HTTP_HOST'] option, which you can correct by passing a --url value in the command.

babbage’s picture

Title: Unsubscribe link in Simplenews footer is http://default with Domain Access module » Unsubscribe link in Simplenews footer is http://default when cron run from drush without --uri parameter
Project: Domain » Simplenews
Version: 7.x-3.4 » 7.x-1.x-dev
Category: support » task

Fabulous. Thanks agentrickard, you've hit the nail on the head and it wasn't an angle I'd even considered. The newsletters are sent out on cron, and I was running drush cron to make it happen immediately. Using drush cron --uri=example.com fixes the problem.

Will check this, but seems highly likely this isn't even associated with Domain Access module after all, and would happen on any site where the site is installed in sites/all/default and where newsletters are sent after cron is run from drush without a uri parameter specified. I hadn't seen this on my other site where I was using Simplenews, so wondered if it was associated with using Domain Access on this site, but it seems more likely I just was running the cron via the web browser when testing the setup on the other site.

Moving to Simplenews issue queue. I'll have a look at this further to confirm the limits around the circumstances in which this occurs.

miro_dietiker’s picture

Yes this is a known issue.
Basically it possibly lacks documentation.

In my opinion, this is a bug of drush or even drupal core.
"default" or "localhost" is just NO reasonable default. Instead the system should apply its known base URL.
Note that with multisites this is not really clear... So if you check the drush documentation, it states:
"URI of the drupal site to use (only needed in multisite environments)"
This means, drush can not provide any reasonable default for these cases...

I'm happy if you can help us improving the documentation.
Also i suggested to the drush team once to completely ban drush executions without uri parameter in case of multisites.
Also we considered stopping cron excution if w detect cases such as "default" or "localhost".

But basically no one feels responsible for such a messy result.
What i can say for sure is: Simplenews is the wrong place to fix it. We just could detect the failure and avoid sending out spam.

agentrickard’s picture

Well, specific to this issue, DA does require a URL parameter, because you may wish to send newsletters from specific domains.

I think this is a documentation issue (possibly for Drush), but its covered in the DA docs (and cron) as well.

Any cron implementation is supposed to pass a valid URL request. See http://drupal.org/cron

agentrickard’s picture

@babbage

And, specific to DA, if you need to send newsletters from various domains, you may need an implementation of hook_domain_cron() as well. See the DA API file.

babbage’s picture

Issue summary: View changes

[headslap] Encountered this issue of my Simplenews footers again having a broken unsubscribe link that was http://default/... Thought I'd mis-edited my footer template. Google brought me back to find myself walking in my own footprints. Must hard-code a solution to this somehow. :)

Edit to add: This is not a problem associated with Domain Access in any way. It occurs if Drush is used to activate cron on any site where the site is installed in the sites/default folder and where a --uri parameter is not passed. See https://github.com/drush-ops/drush/issues/87

babbage’s picture

But basically no one feels responsible for such a messy result.
What i can say for sure is: Simplenews is the wrong place to fix it. We just could detect the failure and avoid sending out spam.

It would be fabulous if Simplenews refused to send out hundreds of newsletters with an invalid unsubscribe link when I ran drush cron without thinking. :)

miro_dietiker’s picture

Patches welcome.

jaylotta’s picture

If you set the base url in settings.php then cron will use that value.

It's not the right solution, but it is a workaround.

miro_dietiker’s picture

I didn't test it recently, but setting a base url in settings.php did NOT affect any drush (cron) call.

See also related task
#2396121: Stop sending via cron without meaningful hostname

ariban99’s picture

any update on this? its still happening on all my different drupal installs!
can anyone help with this?
what if someone does NOT have drush. they simple go to contents > newsletter and push send newsletter (in simplenews, its selected to use cron to send newsletter 200 at a time and cron runs every 3 hours)
any help will be greatly appreciated.

rcodina’s picture

I also reproduced the error.

miro_dietiker’s picture

@ariban99 If you click it in the UI through the browser, the link will point to the current URL domain or the base URL configured.
This really only is a drush issue.

For Drupal 8, we solved this:

function simplenews_cron() {
  if (!simplenews_assert_uri()) {
    return;
  }

function simplenews_assert_uri() {
  $host = \Drupal::request()->getHost();
  // Check if the host name is configured.
  if ($host == 'default') {
    \Drupal::logger('simplenews')->error('Stop sending newsletter to avoid broken links / SPAM. Site URI not specified.');
    return FALSE;
  }
  return TRUE;
}

Backports welcome.