简体   繁体   中英

Copy html fields in email body without php

I need to copy my html form fields in email body. 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 . If possible. Thanks for the help in advance

Done it with only html and 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 = "#";
    }
});

You can do the following:

In your 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:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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