I have a form, and when the form is submitted (input type="submit"), i would like to open the clients default mail-browser with a pre-populated email-message.
So when the user clicks submit two things need to happen. Open email and submit form.
Also, how can i use the values entered in the form to prepopulate the email?
I'm new to javascript-jquery so please, any code example would be of great help!
Thanks for your help!
Before submitting the form you could do:
window.location.href = 'mailto:[email protected]';
this will open the predefined mail client and you can also prefill some field. look at the mailto sintax here or post some more info so that we can help you;
This could be done like this :
$('input[type=submit]').click(function(){
window.location.href = "mailto:" + $('#email').val();
});
I have used a code like this when I needed to send via mailto using my local email client, it may help:
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form id="myform" enctype="text/plain" action="test.php" method="post" >
<input type="text" value="value1" id ="field1" name="field1">
<input type="checkbox" value="valuel2" id ="field2" name="field2" checked>
<input type="checkbox" value="value3" id ="field3" name="field3" >
<textarea id="myText" name ="texty">
Lorem ipsum...
</textarea>
<button onclick="sendMail(); return false">Send</button>
</form>
<script>
function sendMail() {
$myform = $('#myform');
$myform.prop ('action','mailto:[email protected]');
$myform.submit();
}
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With