basically, ive been trying to set up this code for my page, however im struggling as im not the best at javascript. ive tried looking up resources online but none of them seem to help. this is part of a form, i want the users to fill a small form and then, after clicking the button, it should open their mail client with a template. i just need to know how to properly add the information to the javascript, especially how to set up a carbon copy gmail, and if theres anything i should change. i can provide the full form code if needed.
<div class="row">
<input type="submit" value="Enviar." onclick="sendMail(); return false">
</div>
heres the javascript that ive been working with
<script>
function sendMail() {
var link = "mailto:me@example.com"
+ "?cc=myCCaddress@example.com"
+ "&subject=" + encodeURIComponent("This is my subject")
+ "&body=" + encodeURIComponent(document.getElementById('myText').value)
;
window.location.href = link;
}
</script>
mailto is one of many URL Protocols and it's a way for commands to exit the browser and interact with other applications.
you can try this URL API
https://mail.google.com/mail/?view=cm&fs=1&to=[to]&cc=[cc]&bcc=[bcc]&su=[subject]&body=[body]
Although not recommended. Anyone who clicks on it needs to be logged into their gmail account (if they have one), but technically it works if the user has gmail and is logged in.
here is an example on how to combine urls
const combination = (obj) => {
const parameter = Object.entries(obj).map(o => `&${o[0]}=${o[1]}`).join('');
return `https://mail.google.com/mail/?view=cm&fs=1${parameter}`
};
const mail1 = {
su: 'subject',
to: 'someone',
body: 'body',
cc: 'someone',
bcc: 'someone'
}
const mail2 = {
su: 'subject',
to: 'someone',
body: 'body'
}
console.log('mail1', combination(mail1));
console.log('mail2', combination(mail2));