URL/Content Encode for Mailto

Hi, I am trying to output the [[*pagetitle]] and [[~[[* id]]? &scheme= full ]] of a resource such that it is compliant for use in a mailto link. htmlentities output modifier doesn’t seem to work for this purpose. Example:

Mail To: info@domain.com
Subject: How to Get an A+ in Weight Loss
Body: https://www.domain.com/a-in-weight-loss

To:
<a href="mailto:info@activate.com?subject=How%20to%20get%20an%20A+%20in%20Weight%20Loss&body=%3Ca%20href%3D%22https%3A//www.domain.com/a-in-weight-%0Aloss%22%3Ehttps%3A//www.domaincom/a-in-weight-loss%3C/a%3E">your message here</a>

Is there an existing output modifier I’m not seeing in the documentation, or would I have to write a snippet/modifier from scratch? I don’t know PHP (real programming goes over my head), how would I go about that if I need to?

1 Like

Use the URI of the resource instead of [[~]] perhaps. Something like

<a href="mailto:[[*uri:htmlent]]">[[*uri]]</a>

And even if you did have to use PHP, this one would be quite easy. Just create a snippet called “htmlent” or whatever you want.
Then call it and pass in the URL you have like [[htmlent? &url=`[[~[[*id]]]]`]]

Then in the snippet code:

return html_encode($url);

One of those two should help you out.

1 Like

htmlent doesn’t replace spaces with %20 etc, so it’s not really useful.

In the snippet I replaced
return html_encode($url);
with
return rawurlencode($url); and it works perfectly! Thanks!

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

There’s a urlencode output filter already you can use - no custom snippet required.

[[~[[*id]]:urlencode? &scheme=`full`]]

Same for htmlentities - no need for @zackw’s custom snippet. Just use the htmlent output filter.

Actually urlencode doesn’t do what I need it to. I get + instead of %20 for spaces, so I end up with no content in the subject line of an email as a result. I this is the result of differences between rawurlencode() and urlencode() in php. Either way, the snippet does what I need it to, so problem solved. Thanks!