linkit icon indicating copy to clipboard operation
linkit copied to clipboard

Allow mailto: links with subject and body to be added as URLs

Open saltymouse opened this issue 5 years ago • 5 comments

Adding simple mailto links is possible as mentioned in #41, but adding subject or body parameters breaks this features. Is there any chance of updating to accept these additional parameters?

Example: Entering the following into a URL field results in a Please enter a valid email address error.

mailto:[email protected]?subject=Test%20Subject&body=This%20is%20a%20body%20test.

Mailto generator used: https://mailtolink.me/

saltymouse avatar Oct 31 '20 17:10 saltymouse

+1 for that. We would also need that in a project of ours.

christophpaster avatar Nov 12 '20 13:11 christophpaster

@ben-callaway

I've taken a closer look, and found a workaround that cuts the ?subject=... portion of the string (if applicable) and only validates the e-mail itself. I've changed the validation function (starting at line 58 in the file UrlValidator.php) like so:

        if ($this->allowMailto && substr($value, 0, 7) === 'mailto:') {
            $emailValidator = new EmailValidator;

            $position = strpos($value, "?subject=");
            if ($position === false) {
                $emailValidated = $value;
            } else {
                $emailValidated = substr($value, 0, strpos($value, "?subject="));
            }

            if ($emailValidator->validateValue(str_replace('mailto:', '', $emailValidated)))
            {
                return [Craft::t('linkit', 'Please enter a valid email address'), []];
            }
            $this->defaultScheme = null;
            return null;
        }

It's not pretty, but it's a first working solution for our use case. 🙂

martinhellwagner avatar Nov 16 '20 13:11 martinhellwagner

any update on this? Really need to add subject & body to a mailto link

jan-dh avatar Feb 25 '22 11:02 jan-dh

Would like to see this added as well.

CreateSean avatar Feb 06 '24 15:02 CreateSean

This should be supported, to bad it isn't 😢

hipertom avatar Sep 26 '24 10:09 hipertom