复制电子邮件正文中的html字段没有PHP

时间:2017-08-30 17:34:55

标签: javascript html email

我需要在电子邮件正文中复制我的html表单字段。我可以设置其他字段。

发送电子邮件代码:

\1\2

表格代码:

<a href="mailto:karandeep.singh@abc.com?subject=Feedback/Suggestion&bcc=karandeep.singh@abc.com"> Send an Email </a>

我希望将此输入字段复制到正文和电子邮件的主题中,但是用户必须单击发送,它应该只在html或javascript上。 如果可能的话。 感谢您的帮助

2 个答案:

答案 0 :(得分:0)

仅使用html和javascript完成: https://jsfiddle.net/Damian239/fuog3e3L/1/

HTML:

<a id="send-button" href="#">Send</a>
<textarea id="description"></textarea>

使用Javascript:

var href = "mailto:joedoe@gmail.com";

document.getElementById('description').addEventListener('keyup', function() {
    var body = this.value;
    if((body !== "") && (typeof body !== "undefined")) {
        document.getElementById('send-button').href = href + '?body=' + body;   
    } else {
      document.getElementById('send-button').href = "#";
    }
});

答案 1 :(得分:0)

您可以执行以下操作:

在您的HTML中:

<a onclick="setMailTo(this)"> Send an Email </a>


<li><input type="text" id="incidentNum" name="incident" class="field-style field-full align-none"  placeholder="Incident Number" maxlength="10"/>
</li>

在你的Javascript:

function setMailTo(link){
   var incidentNum = document.getElementById("incidentNum").value;
   var href = "mailto:karandeep.singh@abc.com?";
   href += "subject=Feedback/Suggestion for incident:" + incidentNum; //Or anything else you want
   href += "&body=suggestion regarding incident:" + incidentNum; //This will set the body content
   href += "&bcc=karandeep.singh@abc.com";

   link.href = href;
}