创建一个使用javascript打开默认邮件应用程序并附加文件的表单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建一个使用javascript打开默认邮件应用程序并附加文件的表单相关的知识,希望对你有一定的参考价值。
我被要求创建一个脚本,该脚本从表单和用户输入的文件中获取值。然后,它有一个提交按钮,在客户端的计算机上打开默认邮件应用程序,并使用结构化方式从表单中检索的值填充电子邮件正文。
除了获取用户上传的文件并将它们附加到默认邮件应用程序之外,我已经能够创建一个可以完成所有操作的表单。我在互联网上到处搜索,我没有运气!有人可以帮我完善这个。我已经失去了将近3个星期了!
以下是我写的完整代码,包括表格:
<script type="text/javascript">
function update_message_body() {
var file = document.input_form.file.value;
var awb = document.input_form.awb.value;
var dtsnr = document.input_form.dtsnr.value;
var incoterms = document.input_form.incoterms.value;
var TypeOfGoods = document.input_form.ToG.value;
var DescriptionOfGoods = document.input_form.DoG.value;
var quantity = document.input_form.quantity.value;
var UnitMeasure = document.input_form.um.value;
var ValueOfGoods = document.input_form.VoG.value;
var TotalWeight = document.input_form.tw.value;
var ClearingAgent = document.input_form.ca.value;
var DEtoCA = document.input_form.DEtoCA.value;
var CDUNHRD = document.input_form.CDUNHRD.value;
document.proxy_form.Information.value =
"\n" + "\n" + "This email is to inform you of the details acquired from new record :" + "\n" + "\t Uploaded Attachment :" + file + "\n" + "\t AWB :" + awb + "\n" + "\t Date and time shipping notification recieved :" + dtsnr + "\n" + "\t Incoterms :" + incoterms + "\n" + "\t Types of Goods :" + TypeOfGoods + "\n" + "\t Description of Goods :" + DescriptionOfGoods + "\n" + "\t Quantity :" + quantity + "\n" + "\t Unit Measure :" + UnitMeasure + "\n" + "\t Value of Goods :" + ValueOfGoods + "\n" + "\t Total Weight :" + TotalWeight + "\n" + "\t Clearing Agent :" + ClearingAgent + "\n" + "\t DE set to Clearing Agent :" + DEtoCA + "\n" + "\t When cargo is delivered to UNHRD :" + CDUNHRD + "\n" + "\n" + "\n" + "\n" + "Sincerely,\n";
} < /script>
<style> .dotted {
border-style: dotted;
padding-top: 30px;
padding-right: 30px;
padding-bottom: 30px;
padding-left: 30px;
}
</style>
<!DOCTYPE html>
<html>
<body>
<form name="input_form">
<table class="dotted">
<tr>
<td>Attachment:
<input type="file" name="file" maxlength=50 allow="file_extension">
</td>
</tr>
<tr>
<td>AWB:
<input name="awb" type="text" pattern="[0-9]{9}" required>
</td>
</tr>
<tr>
<td>Date and time shipping notification recieved:
<input name="dtsnr" type="datetime-local" required>
</td>
</tr>
<tr>
<td>
Incoterms:
<select name="incoterms" required>
<option>CIF</option>
<option>DAP</option>
<option>ABC</option>
<option>DEF</option>
<option>GHI</option>
<option>JKL</option>
</select>
</td>
</tr>
<tr>
<td>
Types of Goods:
<select name="ToG">
<option>Biscuit</option>
<option>Tent</option>
<option>Car</option>
<option>Medical Kit</option>
</select>
</td>
</tr>
<tr>
<td>Description of Goods:
<input type="text" placeholder="Description of Goods" required name="DoG">
</td>
</tr>
<tr>
<td>Quantity:
<input type="text" pattern="{9}" name="quantity" required>
</td>
</tr>
<tr>
<td>
Unit Measure:
<select name="um" required>
<option>EA</option>
<option>BX</option>
<option>Pallet</option>
<option>20' container</option>
<option>40' container</option>
</select>
</td>
</tr>
<tr>
<td>Value of Goods:
<input type="text" pattern="{9}" name="VoG" required>
</td>
</tr>
<tr>
<td>Total Weight:
<input type="text" pattern="{9}" name="tw" required>
</td>
</tr>
<tr>
<td>Clearing Agent:
<input type="text" name="ca" required>
</td>
</tr>
<tr>
<td>DE set to Clearing Agent:
<input type="date" name="DEtoCA" required>
</td>
</tr>
<tr>
<td>When cargo is delivered to UNHRD:
<input type="date" class="textbox" name="CDUNHRD" required>
</td>
</tr>
</table>
</form>
<form name="proxy_form" method="post" enctype="text/plain" action="mailto:?subject=Inbound Form" onSubmit="return update_message_body();">
<input type=hidden name="Information">
<input type=submit value="send mail">
</form>
</body>
</html>
答案
我99.999%肯定你不能那样做。您可以设置收件人,主题,某些标题和正文,但不能设置附件;例如,在the RFC for the mailto:
protocol中没有关于附件的内容,并且它提到单词“file”(在其中一个示例中)的唯一地方似乎是编辑错误,与附加文件无关。
以上是关于创建一个使用javascript打开默认邮件应用程序并附加文件的表单的主要内容,如果未能解决你的问题,请参考以下文章
使用 php、javascript 等创建一个电子邮件投递箱