0

I have a webform where end-users can upload images files. My office users were reporting that when they received and email notice of a submission, the links to the images are broken.

I was working on updating the email template for webform submissions. I created webform-mail-34981.tpl.php, which is the nid of the webform in question.

First I broke the fields out into separate tokens, but I still got broken links.

Tokens in expressions such as this

[submission:values:photo_5]
[submission:values:photo_5:nolabel]

gave relative links, with out the domain name, like this

<a href='/sites/default/files/webform/index4_17.jpg'>www.example.com/sites/default/files/webform/index4_17.jpg</a>

As you can see, when the user would click on that link, the browser says it can't find the server, because it has a relative path.

Thinking it was a problem with the token, I added code to construct the anchor tag from the fid:

foreach ( $fids as $fid ) {
  $file = file_load($fid);
  $url = file_create_url($file->uri);
  echo "Plain URL: $url<br>\r\n";
  echo "Anchor tag: <a href='$url'>$url</a><br>\r\n";
}

To my suprise, I still got links with the correct URL value in the anchor tag, but a relative path in the href!

In doing some debugging, I added a die() statement to the template, so that I would see the template before it had its tokens replaced. I was further surprised when I saw that the template output had FQDNs in the href propreties:

Photo 4
[submission:values:photo_4]
[submission:values:photo_4:nolabel]

Photo 5
[submission:values:photo_5]
[submission:values:photo_5:nolabel]

Plain URL: http://example.com/sites/default/files/webform/index2_36.jpg<br>
Anchor tag: <a href='http://example.com/sites/default/files/webform/index2_36.jpg'>http://example.com/sites/default/files/webform/index2_36.jpg</a><br>

So, in webform-mail-34981.tpl.php, the URI values in the href of the tags are FQDNs, which is what we want. Some time after, they are being replaced with relative paths, which are broken for end-users.

When/where is this happening? I did not create the site, I'm just a contractor working on it, so I'm not aware offhand if there is custom code that might be doing this.

We do have webform-mail.php, but it appears to be a stock template. It doesn't seem to have any code that would make paths relative:

<?php print ($email['html'] ? '<p>' : '') . t('Submitted on: [submission:date:long]'). ($email['html'] ? '</p>' : ''); ?>

<?php if ($user->uid): ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by user: [submission:user]') . ($email['html'] ? '</p>' : ''); ?>
<?php else: ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by anonymous user: [submission:ip-address]') . ($email['html'] ? '</p>' : ''); ?>
<?php endif; ?>

<?php print ($email['html'] ? '<p>' : '') . t('Submitted values are') . ':' . ($email['html'] ? '</p>' : ''); ?>

[submission:values]

How can I find out where this is happening?

Edit I've installed the mail_logger module to try to get a more objective look at what is going on. It looks like something in the templating system is re-writing absolute links into relative links.

Mail Type:
webform_submission
Date Sent:
August 20, 2017 - 5:09pm
User IP Address:
127.0.0.1
Mail Class:
HTMLMailSystem
...

Photo 1<br /><a href="/sites/default/files/webform/my_export.png">my_export.png</a><br /><a href="/sites/default/files/webform/my_export.png">my_export.png</a></p>
<p>Plain URL: <a href="/sites/default/files/webform/my_export.png">http://mysite.dev.dd:8083/sites/default/files/webform/my_export.png</a><br /><br />
Anchor tag: <a href="/sites/default/files/webform/my_export.png">http://mysite.dev.dd:8083/sites/default/files/webform/my_export.png</a><br /></p></div>

Edit 2

I've been doing some more troubleshooting. Found two more pieces of information:

  1. HTMLMimeMail mail system is causing the links to change. When I removed HTMLMimeMail from the webmail key, then plan text emails had the full link.

  2. Pathologic is not re-writing the link either way. I looked at pathologic settings on our site, and it was initially set to relative URLs. I thought this might be the cause of the problem, but I changed it to absolute paths. I still got links with relative paths. To make a stronger test, I specified the domain name to example.com in pathologic settings. I still got relative links in the email (I cleared the cache after changing pathologic settings). So, I believe pathologic can be ruled out.

Edit 3 I debugged the final output of the HTMLMailSystem::format() method, and at the end of the function, the output has the domain name in the links. I'm presently at a loss for the next thing to look at, would appreciate any help.

  • Something similar with Views was documented and "fixed" ... perhaps there's a tokenization that is santizing the urls. drupal.org/node/2488540 – joshmiller Aug 22 '17 at 19:13
1

I don't know if this answer causes this question to be disqualified on this site, but it turns out that the pathologic module is causing relative links.

I disabled the pathologic module on a dev environment, and now the links are no longer relative.

I'm working on troubleshooting the settings to keep my links from becoming relative.

0

Try to change the weight of your custom module in order run after pathlogic module, So you can keep pathlogic module enabled without affecting your code.

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.