最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - On form submit, mailto from javascript with form values - Stack Overflow

programmeradmin6浏览0评论

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!

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!

Share Improve this question asked Jul 30, 2011 at 9:46 user829237user829237 1,7698 gold badges38 silver badges62 bronze badges 2
  • 1 You want...javascript to handle this? I would prefer PHP at least. – ngen Commented Jul 30, 2011 at 9:49
  • 1 The thing is that i cant use serverside emailing, because one of the requirements is that the email must be sent from the clients own email client so that the message will appear in his outbox. – user829237 Commented Jul 30, 2011 at 10:34
Add a ment  | 

3 Answers 3

Reset to default 3

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./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>

you can prepopulate form with

$("textarea").val('Your message here! You\' have to strip \'');

if it's default email clien't, I'm afraid it's not possible

发布评论

评论列表(0)

  1. 暂无评论