Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On form submit, mailto from javascript with form values

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!

like image 843
user829237 Avatar asked Oct 10 '22 09:10

user829237


2 Answers

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();
});
like image 88
Nicola Peluchetti Avatar answered Oct 20 '22 06:10

Nicola Peluchetti


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>
like image 21
daniel Avatar answered Oct 20 '22 05:10

daniel