Allow mailto: links with subject and body to be added as URLs
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/
+1 for that. We would also need that in a project of ours.
@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. 🙂
any update on this? Really need to add subject & body to a mailto link
Would like to see this added as well.
This should be supported, to bad it isn't 😢