Home > Software design >  HTML form mailto: Mail body is empty, no matter what got filled out
HTML form mailto: Mail body is empty, no matter what got filled out

Time:10-19

I'm trying to make a simple html form, that can then be sent as a Mail on submitting. Here's some example code from w3docs.com:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <h2>Give Feedback to Our Website.</h2>
    <form action="mailto:[email protected]" method="get" enctype="text/plain">
      <div>
        <label for="name">Name:
          <input type="text" name="name" id="name" />
        </label>
      </div>
      <div>
        <label for="email">Email:
          <input type="text" name="email" id="email" />
        </label>
      </div>
      <div>
        <label>Comments:</label>
        <br />
        <textarea name="comments" rows="12" cols="35">Send your comments to us.</textarea>
      </div>
      <div>
        <input type="submit" name="submit" value="Send" />
        <input type="reset" name="reset" value="Clear Form" />
      </div>
    </form>
  </body>
</html>

As you can see, this should open the mail client with a prefilled mail for [email protected]. However, the mail always ends up being empty.

Since this is copied code, that should work, I'm not sure what I'm doing wrong here.

CodePudding user response:

Try this :

<textarea name="body" rows="12" cols="35">Send your comments to us.</textarea>

By using GET parameters you can play with the subject or the body by doing so:

mailto:[email protected]?body=whatever&subject=whatever

CodePudding user response:

In Your case to open the mail client with a prefilled mail, You should change method to post in Your form tag. and That's it.


example snippet

<form action="mailto:[email protected]" method="post" enctype="text/plain">
  • Related