从HTML发送电子邮件

时间:2015-07-04 22:01:30

标签: html email html-form

<form action="MAILTO:myemail@example.com" method="post" enctype="text/plain">
    <input type="text" value="Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}" required="">
    <input type="text" value="E-mail" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'E-mail';}" required="">
    <textarea type="text" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}" required="">Message</textarea>
    <input type="submit" value="SEND">
</form>

上面的代码在我的HTML文件中。一旦我在文本框中写入文本并单击提交按钮,它就会使用我的电子邮件客户端打开一封新电子邮件(到目前为止一直很好)。但是,电子邮件正文中没有任何内容。我希望我输入的文本位于刚刚打开的新电子邮件的正文中。我不想使用任何PHP或JavaScript文件。我希望所有内容都在HTML文件中。

谢谢!

1 个答案:

答案 0 :(得分:0)

name=body添加到您的文字区域

<textarea name='body' ... ></textarea>

每个其他输入可以分配给电子邮件消息的不同行(即主题行,行,cc等)。您需要做的就是设置&#34; name&#34;每个输入到您希望它出现的电子邮件行的属性。

如果您希望输入您的姓名作为邮件的主题,请添加`name =&#39; subject&#39;你的名字输入。

https://en.wikipedia.org/wiki/Mailto

此外,您应该将方法更改为&#39; GET&#39;在使用encodeURI(value of the textarea)

发送数据之前强制执行URI编码