stats_noob
stats_noob

Reputation: 5897

Sending an Email Through HTML

I found the following HTML code for sending an e-mail:

<html>
   <body>
      <h2> Questions? Send an e-mail! </h2>
      <form action="mailto:[email protected]" method="post" enctype="text/plain">
         Name:<br>
         <input type="text" name="name"><br>
         E-mail:<br>
         <input type="text" name="mail"><br>
         Comment:<br>
         <input type="text" name="comment" size="50"><br><br>
         <input type="submit" value="Send">
         <input type="reset" value="Reset">
      </form>
   </body>
</html>

Since I am using the R programming language, I copied this HTML code into an R Markdown editor and then ran the code:

enter image description here

When I click send, I get the following window:

enter image description here

Is it possible to modify this HTML code so that only the message text appears in the e-mail body? For example:

enter image description here

Any ideas on how to do this?

Thank you!

Upvotes: 0

Views: 84

Answers (1)

Kat
Kat

Reputation: 18714

This works for an RMD output set to html_document. You needed to identify the email as an email and the body as the body (comment isn't recognized).

Notice that each part of the form is wrapped in a label.

Let me know if you have questions.

<body>
  <h2> Questions? Send an e-mail! </h2>
  <form action="mailto:[email protected]" method="get" enctype="text/plain">
    <div>
      <label for="name">Name:<br>
    <input type="text" name="name" id="name" /><br>
    </label>
    </div>
    <div><label for="email">Email:<br>
    <input type="text" name="email" id="email" /><br>
    </label>
    </div>
    <div>
      <label for="body">
    Comment:<br>
    <textarea name="body" placeholder="Send your comments."></textarea><br><br>
    </label>
    </div>
    <div>
      <input type="submit" value="Send" name="submit" />
      <input type="reset" value="Reset" name="reset" />
    </div>
  </form>
</body>

---
title: "Untitled"
author: "me"
date: "2022-10-23"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```

<body>
<h2> Questions? Send an e-mail! </h2>
<form action="mailto:[email protected]" method="get" enctype="text/plain">
<div>
<label for="name">Name:<br>
<input type="text" name="name" id="name" /><br>
</label>
</div>
<div><label for="email">Email:<br>
<input type="text" name="email" id="email" /><br>
</label>
</div>
<div>
<label for="body">
Comment:<br>
<textarea name="body" placeholder="Send your comments."></textarea><br><br>
</label>
</div>
<div>
<input type="submit" value="Send" name="submit" />
<input type="reset" value="Reset" name="reset" />
</div>
</form>
</body>

Upvotes: 1

Related Questions