使用:表单 action mailto发邮件

 
怎样通过HTM页面直接提交到Email的表单
 
解决思路: 
关键点是设置表单的action属性为”mailto:”+email地址。
 
(方法一) 具体步骤: 
1.设置表单的action属性为接收邮件的email地址,并设置表单的MIME编码。 

<form action="mailto:yourname@domain.com" enctype="text/plain"> 
</form> 

2.设置邮件主题和正文的输入框 

主题:<input name="subject" type="text"><br> 
正文:<textarea name="body"></textarea><br> 

<input name="subject" type="text"> 

3.设置抄送和密码地址输入框 

抄送:<input name="cc" type="text"><br> 
密送:<input name="bcc" type="text"><br> 

4.完整代码 

<form action="mailto:yourname@domain.com" enctype="text/plain"> 
主题:<input name="subject" type="text"><br> 
抄送:<input name="cc" type="text"><br> 
密送:<input name="bcc" type="text"><br> 
正文:<textarea name="body"></textarea><br> 
<input type="submit"> 
</form> 

注意: 
l          表单的action值的格式必须为"mailto:目标Email地址",这个跟做Email链接时类似。 
l          enctype(MIME编码)必须设置为"text/plain"(文本),否则收到的邮件是乱码。 
l          表单的method属性不能设置为post,必须为get(默认不设置时为get),否则邮件的格式跟用户输入的不符合。 
 
(方法二) 具体步骤:
<a href="mailto:youname@domain.com?subject=title&cc=name1@domain.com,name2@domain.com&bcc=bccname@domain.com&body=hello world!">mailto</a> 
 
 
案例
HTML代码:
<form name="form" method="post" action="mailto:service@kashuo.com" enctype="text/plain">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th>姓名</th>
            <td><input type="text" name="name" class="popup-btn"></td>
        </tr>
 
        <tr>
            <th>联系电话</th>
            <td><input type="text" name="iphone" class="popup-btn"></td>
        </tr>
 
        <tr>
            <td></td>
            <td><input name="close"  type="bottn" οnclick="getMailtoUrl()" class="popup-btn popup-btn1" value="提交申请">
            </td>
        </tr>
    </table>
</form>
 
JS代码:
<script type="text/javascript">
    function getMailtoUrl() {
        var args = [];
        if (typeof subject !== 'undefined') {
            args.push('subject=' + encodeURIComponent('主题内容'));
        }
        var name = $("input[name='name']").val();
        var iphone = $("input[name='iphone']").val();
        var body = name +"\n"+iphone
        if (typeof body !== 'undefined') {
            args.push('body=' + encodeURIComponent(body))
        }
 
        var url = 'mailto:' + encodeURIComponent('service@kashuo.com');
        if (args.length > 0) {
            url += '?' + args.join('&');
        }
        console.log(url);
        window.location = url;
        return url;
    }
</script>
 
 
注)参考网站
http://it.taocms.org/10/8905.htm
 
 
  • 9
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值