Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send form input by email without server

For a locally hosted HTML page, I need to email a bit of user input (name, email, comments).

This is done on a touchscreen display, where visitors can leave their information and comments.

So I was thinking of using a virtual keyboard such as here.

<form action="post" id="emails" onsubmit="return false;">
<input type="text" id="keyboard" placeholder="Enter name..."></input>
<input type="text"  id="keyboard2" placeholder="Enter email..."></input>
<input type='submit' id='send' value='Submit' />
</form>

I used this to be able to send the email link.

And with the correct details, the following code works and I get emails in my inbox.

$('#send').click(function() {
    $.ajax({ 
        type: 'POST',
        url: 'https://mandrillapp.com/api/1.0/messages/send.json',
        data: {
            'key': "xxxxxxxx",
            'message': {
            'from_email': "[email protected]",
            'to': [
            {
            'email': "[email protected]",
            'name': 'xxxxxx',
            'type': 'to'
            }
            ],
            'autotext': 'true',
            'subject': 'TEST! TEST!',
            'html': 'test'
            }
        }
    }).done(function(response) {
        console.log(response);
        alert("You send an email!"); // if you're into that sorta thing
    });
});

So this works, as in it sends the email with the text put in here: 'html': 'test'

And instead of 'test', I would obviously like to get 'name + email'.

(Also it is probably for less then 50 emails per month, so just an email will suit my needs for now, nothing with databases and saving all this data. I would just like to get the email.)

So, is it possible and how should I do this?

Is the route I took now doable or would you suggest a completely different way?

like image 359
marty90 Avatar asked Jun 29 '26 02:06

marty90


1 Answers

// do everything inside after page load.
$(function() {
    $('#send').click(function() {
        // get values of inputs...
        var name = $('#keyboard').val(),
            email = $('#keyboard2').val();

        $.ajax({ 
            type: 'POST',
            url: 'https://mandrillapp.com/api/1.0/messages/send.json',
            data: {
                'key': "xxxxxxxx",
                'message': {
                'from_email': "[email protected]",
                'to': [
                {
                'email': "[email protected]",
                'name': 'xxxxxx',
                'type': 'to'
                }
                ],
                'autotext': 'true',
                'subject': 'TEST! TEST!',
                'html': 'Name: ' + name + '\nEmail: ' + email // and use it!
                }
            }
        }).done(function(response) {
            console.log(response);
            alert("You send an email!"); // if you're into that sorta thing
        });
    });
});
like image 135
rgtk Avatar answered Jun 30 '26 17:06

rgtk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!