2

I have a form as part of a website and I just want it to use the mailto attribute to send all of the information to a selected email address however when I press the submit button at the moment, my email client opens with the correct email to send to but no subject or body. Any ideas what I've got to add or done wrong?

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

Thanks everyone!

Termininja
  • 6,620
  • 12
  • 48
  • 49
bchards
  • 294
  • 1
  • 5
  • 23
  • Possible duplicate of [Mailto on submit button](http://stackoverflow.com/questions/12626940/mailto-on-submit-button) – Asons Jan 10 '16 at 22:11
  • Check the accepted answer and the dupe link and you'll see you need to set the right `name` attribute on your input fields. – Asons Jan 10 '16 at 22:14

1 Answers1

2

You forgot to set the name attribute! The subject you can set as a parameter (subject) on the email address. Try the following code:

<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>
Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87
  • Thank you for you help, this worked for me. When the time limit is over I will accept your answer! Very speedy! – bchards Jan 10 '16 at 22:17