使用自定义字段从表单创建mailto [英] Create mailto from form with custom fields

查看:121
本文介绍了使用自定义字段从表单创建mailto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含3个字段(名称,电子邮件和消息)的HTML表单,我想用这3个字段创建自定义mailto,但是我不想创建这样的固定内容:

I have a HTML form with 3 fields (Name, E-Mail and Message) and I want to create a custom mailto with this 3 fields but I don't want create a fixed content like this:

<a href="mailto:mail@company.com?subject=Subject&body=HelloWorld">Send a mail</a>

这可能吗?如果不是,我是否还有另一种方法可以做简单的配方?我的页面是登录页面,只有HTML,CSS和一些JavaScript(也是Bootstrap).

Is this possible? If it isn't, do I have another way to do a simple formulary? My page is a landing page and only have HTML, CSS and some JavaScript (Bootstrap too).

---编辑---

例如,我发现了这一点: http://www.techrepublic.com/article/set-up-an-html-mailto-form-without-a-back-end-script/

I found this, for example: http://www.techrepublic.com/article/set-up-an-html-mailto-form-without-a-back-end-script/

但是它在体内写入了太多信息,结果是字面意思:

But it write too much information in the body, the result is literal:

Name=Your name
E-mail=mail@company.com
Comment=Testing textarea 
Submit=Submit

推荐答案

经过深入的搜索,我可以解决自己的问题.

I can answer myself, after a deep search I could fix my problem.

JavaScript:

JavaScript:

function sendMail() {
    var name = $('#contact #name').val();
    var email = $('#contact #email').val();
    var message = $('#contact textarea').val();
    window.location.href = 'mailto:mail@company.com?subject=The subject - ' + name + ' (' + email + ')' + '&body=' + message;
};

HTML:

<form> 
    <input type="text" id="name" name="name" >
    <input type="email" id="email" name="email">
    <textarea rows="5"></textarea>
</form>
<button type="submit" class="btn btn-primary" onclick="sendMail()">Button Text</button>

我们不能使用提交输入,因为 window.location.href 不能使用它.我们需要使用一个可以运行功能的按钮.

We can't use a submit input, because window.location.href doesn't work with it; we need to use a button who will run a function.

全部,非常简单:)

这篇关于使用自定义字段从表单创建mailto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆