仅使用 HTML 正确填充电子邮件 [英] Properly populate an email using only HTML
问题描述
对于作业,我需要在我的网页中放置一个表单
,并让该表单填充一封电子邮件以供用户发送.
For an assignment, I need to put a form
in my webpage, and have the form populate an email for the user to send.
我在四处寻找后写了这个:
I wrote up this after searching around:
<form enctype="text/plain" method="post" action="mailto:[My Email Here]">
<input type="text" name="subject" value="Subject" />
<input type="text" name="body" value="Body" />
<input type="submit" name="submit" value="Submit" />
</form>
正如我所料,它打开了我的邮件客户端并为我填充了一封电子邮件.问题是,它的填充方式非常丑陋且不直观.主题行留空,正文填充:
Which, as I expected opens my mail client and populates an email for me. The problem is, the way it's populated is quite ugly and unintuitive. The subject line is left blank, and the body is filled with:
subject=Subject
body=Body
submit=Submit
(4 lines of white-space)
理想情况下,我希望主题"以主题结尾,正文"字段是唯一以正文结尾的内容,而提交"则根本不会出现在用户面前.
Ideally, I'd like the "subject" to end up in the subject, the "body" field to be the only thing that ends up in the body, and the "submit" to not appear to the user at all.
这可能吗?
此时我只被允许使用 HTML.(纯 HTML.不允许内联脚本).
I am only allowed to use HTML at this point. (Solely HTML. No inline scripting allowed).
推荐答案
GET 而不是 POST
将表单的方法从 POST
更改为 GET
.使用 GET
方法会将 input
字段中的键/值对作为查询字符串附加到 mailto:
链接上的 action
属性.这将创建一个电子邮件客户端了解如何解析的 URL:
GET instead of POST
Change the form's method from POST
to GET
. Using the GET
method will append the key/value pairs from the input
fields as a query string on the mailto:
link in the action
attribute. This creates a URL that email clients understand how to parse:
mailto:{TARGET EMAIL ADDRESS}?subject=Subject&body=Body
<form enctype="text/plain" method="GET" action="mailto:{TARGET EMAIL ADRESS}">
<input type="text" name="subject" value="Subject"/>
<input type="text" name="body" value="Body"/>
<input type="submit" name="submit" value="Submit">
</form>
这篇关于仅使用 HTML 正确填充电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!