Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send an HTML Form in an Email .. not just MAILTO

Tags:

html

forms

I have an HTML form for people to fill out, and I want it so when they click the submit button, it will just send the email, not bring up their email and ask them to send the message themselves.

When I use:

<form action="MAILTO:[email protected]"... > 

All that does is open up a new window and populates the body of the email, but I want it to just send an email.

And is there a way to format the output of what the email will look like? Instead of just a list of the field names and the entered value.

Thanks.

like image 990
Joe W Avatar asked Sep 16 '11 20:09

Joe W


People also ask

How do you send HTML form content to email?

There is no feature in HTML to send the form submission directly to an email address. What about “mailto” ? Using mailto: You can set the action field of the form as 'mailto'. In this case, the web browser invokes the email client to send the form submission to the email address specified.

Can a form be embedded in an email?

One method to include a form in an email is embedding it straight into email content. According to a study by GetFeedback, embedded feedback emails increases user engagement by up to 210% in comparison to the traditional feedback email.


2 Answers

> 2021 Answer = Easy Way using GMail (5 Mins)

We had a similar challenge to solve yesterday, and we solved it using a Google Apps Script!

Send Email From an HTML Form Without a Backend (Server) via Google!

The solution takes 5 mins to implement and I've documented with step-by-step instructions: https://github.com/nelsonic/html-form-send-email-via-google-script-without-server

Brief Overview

A. Using the sample script, deploy a Google App Script

Deploy the sample script as a Google Spreadsheet APP Script: google-script-just-email.js

3-script-editor-showing-script

remember to set the TO_ADDRESS in the script to where ever you want the emails to be sent.
and copy the APP URL so you can use it in the next step when you publish the script.

B. Create your HTML Form and Set the action to the App URL

Using the sample html file: index.html create a basic form.

7-html-form

remember to paste your APP URL into the form action in the HTML form.

C. Test the HTML Form in your Browser

Open the HTML Form in your Browser, Input some data & submit it!

html form

Submit the form. You should see a confirmation that it was sent: form sent

Open the inbox for the email address you set (above)

email received

Done.

Everything about this is customisable, you can easily style/theme the form with your favourite CSS Library and Store the submitted data in a Google Spreadsheet for quick analysis.
The complete instructions are available on GitHub:
https://github.com/nelsonic/html-form-send-email-via-google-script-without-server

like image 104
nelsonic Avatar answered Sep 23 '22 15:09

nelsonic


You are making sense, but you seem to misunderstand the concept of sending emails.

HTML is parsed on the client side, while the e-mail needs to be sent from the server. You cannot do it in pure HTML. I would suggest writing a PHP script that will deal with the email sending for you.

Basically, instead of the MAILTO, your form's action will need to point to that PHP script. In the script, retrieve the values passed by the form (in PHP, they are available through the $_POST superglobal) and use the email sending function (mail()).

Of course, this can be done in other server-side languages as well. I'm giving a PHP solution because PHP is the language I work with.

A simple example code:

form.html:

<form method="post" action="email.php">     <input type="text" name="subject" /><br />     <textarea name="message"></textarea> </form> 

email.php:

<?php     mail('[email protected]', $_POST['subject'], $_POST['message']); ?> <p>Your email has been sent.</p> 

Of course, the script should contain some safety measures, such as checking whether the $_POST valies are at all available, as well as additional email headers (sender's email, for instance), perhaps a way to deal with character encoding - but that's too complex for a quick example ;).

like image 42
mingos Avatar answered Sep 21 '22 15:09

mingos