简体   繁体   中英

Generate email using JavaScript

I have done a full day of research on this issue and I've come up with nothing. There are many scripts out there to create a client-side email using JS. In my case, I have successfully been able to append a phone number to a number of domain extensions.

This is an example result of this fiddle ...

4808565309@message.Alltel.com;
 4808565309@txt.att.net;
 4808565309@myboostmobile.com;
 4808565309@sms.mycricket.com;
 4808565309@mymetropcs.com;
 4808565309@messaging.sprintpcs.com;
 4808565309@page.nextel.com;
 4808565309@vtext.com;
 4808565309@tmomail.net;
 4808565309@email.uscc.net;
 4808565309@vmobl.com

Now, what I'm trying to do is use an onClick reference to carry these emails into a client-side email client (Outlook in my case).

This is similar to a mailto: , but appending the entire textarea class to the mailto: is my goal.

Any thoughts?

If you're wanting to do multiple recipients, there's no guaranteed safe way to do that. See this post: http://www.sightspecific.com/~mosh/www_faq/multrec.html

If I understand correcting, you are trying to prompt an e-mail message to the users default e-mail client with a pre-populated "to" field with multiple e-mails.

<a href="mailto:email_address">E-mail</a>

If you are trying to prompt the e-mail on the button click, you can attempt to use the mailto window.location.href. However, it is very possible that it would be rejected by some browsers.

Your best bet, is to remove the submit button and changed it to a standard A tag link (you can style it like a button). Upon change of the text field, update the mailto link HREF based on the text field:

http://jsfiddle.net/N3kJb/10/

working fiddle (when click to setVal I have set a new function that open your mailclient)

try this

http://jsfiddle.net/7QUmU/1/

$(document).ready(function () {
    $('#setVal').on('click', function () {
        // Get the phone number.
        var input = $('.input').val();
        var vals = $('.combine').map(function () {
            var value = $.trim(this.value)
            // Append the phone number before the value.
            return value ? input + value : undefined;
        }).get();
        //Add the phone number to the beginning of the array
        vals.unshift();
        $('#outputAddress').val(vals.join(';\n '))
    });

    $('#setVal').on('click', function () {
        window.open('mailto:'+ $("#input2").val() + '?subject=test&body='+ $("#outputAddress").val()+ '');     
    });

});

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