How can I send a form's contents over e-mail w

2019-08-22 13:49发布

问题:

I've got a feedback HTML form, the results of which I need to send to an e-mail address. How do I do that in JavaScript?

回答1:

You can't. You will need to use some sort of background technology, such as python, ruby, coldfusion, php or ASP in order to send it to your email.

There's a few free services on the nets that will allow you to do that using their own resources, but if you are dealing with secure information, you better use your own resources.

Here's a free PHP service that will allow you to do something like that, but just remember that this kind of service is normally unreliable.



回答2:

Your only option is to submit it is a regular form and then send on server side.



回答3:

One way you can attempt to do this is have a

<form action="mailto:example@example.com">

when submitting this will attempt to email the form to the given email address, this is a pretty nasty solution as it relies on the client having a correctly configured mail client. Also you have no controll over the presentation of the email. see Beware of Form Mailto Action for some of the pitfalls.



回答4:

Impossible, for only with javascript, but with the help of server side script, you could.

Please take a look php mail function here



回答5:

Other than possibly AJAX I know of no other way.

EDIT: To clarify - AJAX would call another function like PHP to actually send the mail. You'd need to implement it serverside.

EDIT2: Here's an article



回答6:

You have two options:

1) Use a mailto link. Javascript isnt really necessary although you could use Javascript to "click" the mailto link. This will cause the user's email client to open with a new email prepopulated with the recipient's email address. mailto links There are numerous reasons why mailto links are unreliable (see comments below). They are not recommended.

2) Submit a form back to the server then send the email from the server. Whatever the server side code is (php, c# etc) should have the ability to send email. This way you can guarantee the email was sent.

You cannot silently send email from the browser. It has to either happen with user assistance or on the server.



回答7:

its impossible :) but, you can use jQuery and backend application, written by python(django), php, asp.net, etc.

Simple jQuery script:

$('#button').click(function(){
    $.post('backend.php',
        {message:$('#message').val(),
         name: $('#name').val(),
         email:$('#email').val()},
         function(data) {
             $('.result').html(data);
         });
});

And PHP script:

<?php
if($_POST['message']) 
{
    $body = "Name: ".$_POST['name'];
    $body .= "<br>Email: ".$_POST['email'];
    $body .= "<br>Message: ".$_POST['message']
    if(mail("yourmail@mail.com","Subjects",$body))
        echo 'true';
    else echo 'false;';
}
?>

its simple, without security fix.



回答8:

You can not do that with pure javascript, you might want to use ajax for that too but yet behind the scenes there should be a server-side language to send the email.



回答9:

If you want something that even comes close to working for a reasonable number of people then, keeping within the constraints of the question, you need to use server side JavaScript (the specifics depend on the particular implementation of SSJS you are using, see Whitebeam for an example).



回答10:

you have to use server side scripting like php or perl

send the form content to the server side php. write using sendmail function in php.

your content will be sent to that email.



回答11:

You cannot send mails with client side javascript. Submit the form to a server side script like PHP/JSP/ASP etc and send mail from that script.