简体   繁体   English

复制电子邮件正文中的html字段而不使用php

[英]Copy html fields in email body without php

I need to copy my html form fields in email body. 我需要在电子邮件正文中复制我的html表单字段。 I am able to set other fields. 我可以设置其他字段。

SEND EMAIL CODE : 发送电子邮件代码:

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

FORM CODE : 表格代码:

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

I want this input field to be copied to body and in subject of the email too, but user has to click on send and it should only on html or javascript . 我也希望将此输入字段也复制到正文和电子邮件的主题中,但是用户必须单击send,并且只能在html或javascript上单击。 If possible. 如果可能的话。 Thanks for the help in advance 我在这里先向您的帮助表示感谢

Done it with only html and javascript: https://jsfiddle.net/Damian239/fuog3e3L/1/ 仅使用html和javascript完成此操作: https : //jsfiddle.net/Damian239/fuog3e3L/1/

HTML: HTML:

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

Javascript: 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 = "#";
    }
});

You can do the following: 您可以执行以下操作:

In your HTML: 在您的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>

In you Javascript: 在您的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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM