Ello!
So I have a lovely looking site running on thunderous-cascaron-280d07.netlify.app
I wanted to obfuscate the email address on the contact page so ma using a netlify function:
exports.handler = async function () {
// hiding email from bots in repo
const names = { first: 'FIRSTNAME' }
const provider = 'DOMAIN.COM'
const constructedEmail = `${Object.values(names)}@${provider}`
console.log('Constructed Email:', constructedEmail);
return {
statusCode: 301,
headers: {
'Cache-control': 'public, max-age=0, must-revalidate',
'location': `mailto:${constructedEmail.replace(/\s/g, '')}`
},
}
}
This works and triggers the email program - however it adds a / to the email address e.g. FIRSTNAME@DOMAIN.com/
I added the regex as I thought maybe it was being added as part of the script but seems it is something else - is there a different way to trigger the mailto or am I missing a setting in Netlify to stop it adding the / ?
I tried the Netlify AI help which suggested using a fetch instead of just calling the function:
exports.handler = async () => {
return {
statusCode: 200,
body: "mailto:NAME@WEBSITE.org"
};
};
if I just return the mailto itself and do a window.location.href = mailtoLink it works but I would love to know why the first method adds the / if anyone knows!