How to make a encoded email-link

I want a simple link with the title “MAIL”. When klicked, the email app should open with my email address inserted. My address should not be visible for bots, so i want to use the Html::email(). I don’t find any examples in the guides for that. Same problem with Html::youtube. Where do i find working examples for this tools? Thanks for helping and sorry for my crappy english.

Where? Kirby has the (email:) kirbytag to easily insert a mailto address into textarea fields.

Html::email(): Html::email() | Kirby CMS. There are no examples, but if you look at the attributes, it does tell you what is expected. Same for Html::youtube().

Sorry… i dont get it. It must be annoying for you with noobs like me…

Where must I write this line from the example:
(email: bastian@getkirby.com text: Send me an email title: Contact me)

And how can I call this parameters in a link like this:

E-Mail mit Betreff „Das ist ein Betreff“

A kirbytag goes into a field that is rendered with the kirbytext() method in your templates, usually a textarea field.

There is no parameter to add a subject line, but you can do it like this:

(email: me@example.com?subject=Dies ist der Betreff text: Send me an email title: Contact me)

The html::email() method is used in your templates.

Nope, we have all been there…

Thank you for your help, but I’am still stuck here.

This link doesn’t work… Whats wrong?

<a href="mailto:<?= html::email('mail@example.com', 'Contact us') ?>">Contact</a>

Html::email() creates the a tag for you (From the docs: "Generates an a tag with mailto:"), don’t put it inside an a tag. So only:

<?= Html::email('mail@example.com', 'Contact us') ?>

This will result in the following HTML if we inspect it in dev tools’ inspector:

<a href="mailto:mail@example.com">Contact us</a>

And this if we look at the source code:

<a href="mailto:&#x6d;&#97;&#105;&#108;&#x40;&#x65;&#120;&#97;&#x6d;&#x70;&#108;&#101;&#46;&#99;&#111;&#x6d;">Contact us</a>

And if you want to add a subject line, you have to add it to the email address in the same way as in the kirbytag example above:

<?= Html::email('mail@example.com?subject=This is the subject line', 'Contact us') ?>

The purpose of the HTML class is to create html tags…

3 Likes

Ah ok, now I get it. Thank you very much.