HTML form email using mailto in form action doesnt work in Internet Explorer

邮差的信 提交于 2019-12-18 09:37:37

问题


A customer of ours has a register.html page with a very simple form that allows users to enter their details for registration to the clients website.

The form action is set to "mailto:clientsemail.client.com?subject=subject". The enctype of the page is set to text/plain and the method is post.

What should happen is that the users email client opens with a new email, with the subject set and the forms text boxes posted into the body of the form. Then the website visitor can simply send the email.

It's not very elegant I know, but its how they have it set up.

Now, this all works as expected and sends a rather clunky looking email to the correct address using the web visitors email client, but only in Firefox, chrome and opera. Safari bugs out completely, and internet explorer opens the email client and populates the address and subject fields, but the form inputs are not copied to the body.

Does anyone know why this is? its driving me nuts. Been looking at it all day and every post I find on the subject states its setup correctly and should work. Theres no mention of it not working in IE.


回答1:


mailto: form actions depend on browsers and local email clients playing together nicely. They do this so rarely that mailto: form actions are unusable on the WWW.

Replace it with a server side program that sends the email.




回答2:


The mailto tag should only accept the following parameters:

  1. cc=name@email.com carbon copy e-mail address
  2. bcc=name@email.com blind carbon copy e-mail address
  3. subject=subject text subject of e-mail
  4. body=body text

All other input parameters are discarded (i.e. FirstName, LastName, etc...)

As a workaround, you can add a hidden body input to the form, and populate it with whatever text you want in the submit event.

Example:

<html>
<head>
<title></title>
</head>
<body>
    <script type="text/javascript">
        function beforeSubmit() {
            var firstName = document.getElementById("FirstName");
            var lastName = document.getElementById("LastName");
            var body = document.getElementById("body");
            body.value = firstName.value + lastName.value;
    }
</script>

    <form action="mailto:me@myemailaddress.com" enctype="text/plain" onsubmit="beforeSubmit()">
        <input name="Subject" id="Subject" type="text" value="" /><br/>
        <input name="FirstName" id="FirstName" type="text" value="" /><br />
        <input name="LastName" id="LastName" type="text" value="" /><br />
        <input name="body" id="body" type="hidden" value="" /><br />
        <input name="Submit" id="submit" type="submit" value="Submit" /><br/>
        <input name="Reset" id="Reset" type="reset" value="Reset" /><br />
    </form>
</body>




回答3:


For some reason IE doesn't like this POST form to email option (works at FF and Chrome)

You should do something like that:

function sendFormToEmail() {
    var inputs = $('#infoForm :input');
    var bodyStr = "";
    inputs.each(function(index, value) {
        bodyStr += value.name + " = " + value.value + "   ,   ";
    });

    window.location = "mailto:Example@gmail.com?subject=subject&body=" + bodyStr;
}

and in your form:

<input type="button" class="button" value="Send Information" onclick="sendFormToEmail()" />


来源:https://stackoverflow.com/questions/28970287/html-form-email-using-mailto-in-form-action-doesnt-work-in-internet-explorer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!