Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saltymouse opened this issue Oct 31, 2020 · 5 comments
Open

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

saltymouse opened this issue Oct 31, 2020 · 5 comments

Comments

@saltymouse
Copy link

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/

@christophpaster
Copy link

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

@martinhellwagner
Copy link

martinhellwagner commented Nov 16, 2020

@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. 🙂

@jan-dh
Copy link

jan-dh commented Feb 25, 2022

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

@CreateSean
Copy link

Would like to see this added as well.

@hipertom
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants