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

2019-08-22 13:06发布

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?

11条回答
2楼-- · 2019-08-22 13:37

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.

查看更多
迷人小祖宗
3楼-- · 2019-08-22 13:40

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

查看更多
放我归山
4楼-- · 2019-08-22 13:40

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.

查看更多
时光不老,我们不散
5楼-- · 2019-08-22 13:44

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.

查看更多
何必那么认真
6楼-- · 2019-08-22 13:48

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.

查看更多
The star\"
7楼-- · 2019-08-22 13:54

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).

查看更多
登录 后发表回答