表单无法正确使用Mailto

时间:2016-01-10 22:06:22

标签: html forms twitter-bootstrap mailto

我有一个表单作为网站的一部分,我只是希望它使用mailto属性将所有信息发送到选定的电子邮件地址,但是当我按下提交按钮时,我的电子邮件客户端打开了正确的电子邮件发送给但没有主题或正文。我有什么想法添加或做错了吗?

<form action="mailto:example@example.com" method="post" enctype="text/plain" class="form-horizontal">
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="name" placeholder="Name">
        </div>
    </div>
    <div class="form-group">
        <label for="company" class="col-sm-2 control-label">Company</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="company" placeholder="Company">
        </div>
    </div>
    <div class="form-group">
        <label for="email" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <input type="email" class="form-control" id="email" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="message" class="col-sm-2 control-label">Message</label>
        <div class="col-sm-10">
            <textarea class="form-control" rows="3" placeholder="Your Message"></textarea>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">Submit</button>
        </div>
    </div>
</form>

谢谢大家!

1 个答案:

答案 0 :(得分:2)

您忘了设置name属性!您可以在电子邮件地址上设置为参数(subject)的主题。请尝试以下代码:

<form action="mailto:example@example.com?subject=Test" method="post" enctype="text/plain" class="form-horizontal">
  <div class="form-group">
    <label for="name" class="col-sm-2 control-label">Name</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="name" id="name" placeholder="Name">
    </div>
  </div>
  <div class="form-group">
    <label for="company" class="col-sm-2 control-label">Company</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="company" id="company" placeholder="Company">
    </div>
  </div>
  <div class="form-group">
    <label for="email" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" name="email" id="email" placeholder="Email">
    </div>
  </div>
  <div class="form-group">
    <label for="message" class="col-sm-2 control-label">Message</label>
    <div class="col-sm-10">
      <textarea class="form-control" rows="3" name="message" placeholder="Your Message"></textarea>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Submit</button>
    </div>
  </div>
</form>