首页 > 解决方案 > 有没有办法使用带有 HTML 的 JavaScript 来上传附加到 HTML 生成的电子邮件的文件?

问题描述

(免责声明:我对 HTML/CSS/JavaScript 很陌生,如果我的代码很古怪,请见谅)

我正在寻找一种方法来生成带有电子邮件附件的电子邮件。这是我的代码:

<body>
  <form action="mailto:example3@example.com" method="GET">
    <label for="cc">Cc Line Addresses:</label>
    <br>
    <input id="cc" name="cc" type="email multiple" value="example1@example.com;example2@example.com"/>
    <br>
    <br>
    <label for="subject" >Enter your subject below:</label>
    <br>
    <input type="text" name="subject" id="subject">
    <br> 
    <br>
    <label for="body" >Enter the Email Body below:</label>
    <br><textarea id="body" name="body" rows="5" cols="50">Example body</textarea>
    <br>
    <br>
    <label for= "myFile">Click below to upload your attachment file</label>
    <!-- This is where I want the attachment to flow to the email-->
    <br>
    <br>
    <input type="file" id="myFile" name="attachment" class="fileUpload">
    <br>
    <br>
    <strong><label for="submit">Click Below to Generate New Email</label></strong>
    <br>
    <input type="submit" id="submit" value="Generate">
  </form>
</body>

我想使用 Javascript 将 HTML 表单中的上传文件附加到提交按钮生成的电子邮件(使用默认电子邮件客户端打开)。

谢谢!

标签: javascriptformshtml-emailemail-attachments

解决方案


尝试添加enctype="multipart/form-data"到您的表单元素。
https://www.w3docs.com/snippets/html/how-to-create-mailto-forms.html


推荐阅读