You are here: Home » All Posts » Javascript Form Handling » Can JavaScript email a form?

Can JavaScript email a form?

in Javascript Form Handling

NO! JavaScript can’t email a form! but, there are alternatives to send the form data to an email address.

There is no direct method provided by JavaScript to send the data submitted in the form to an email address.

The main concern for not providing a ‘JavaScript email form’ feature is security.
Suppose there is a feature in JavaScript to send email. Some malicious coder can write a script to send email to some address immediately when you visit their page. This will reveal your email address to some third party without your knowledge. They will start filling your mail box with lots of spam messages! However, there are alternatives as explained below.

Build Web Forms Faaaast!!

Quickly create your form, install it and receive form submissions by email.
Simfatic Forms : customizable forms Using Simfatic Forms it is very easy to design,
create, install and maintain web forms;
no coding required! Click here for more info

Using ‘mailto:’

You can use ‘mailto:me@mydomain.com’ in the action field of the form. When the user presses the submit button of the form, the browser will first show a warning box that the user’s email address will be revealed to the recipient.
mailto dialog box

If the user decides to proceed, the form data will be sent to the address mentioned in the mailto: tag. The browser will open the default mail client to send the data by email.

Sample Code

<form action="mailto:you@yourdmainhere.com" method="post" enctype="text/plain" >
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>

See the sample code above at work:
JavaScript mail Form Example 1

Notice that this method does not require JavaScript at all.

Disadvantages of ‘mailto:’ method

It is not possible to control the formatting of the form data. The data submitted in the form is sent by the browser. You can’t control the layout of the data.

Browser shows the warning window before sending the data. It may prevent the visitor from submitting the form.

Using Server side script to send email

The right way to send form submissions to email is by receiving the form submissions in a server-side script and then sending the email. The server side scripting language (like PHP Perl, ASP) has more features and facilities to send the email.

Learn More:

Be Sociable, Share!

{ 14 comments… read them below or add one }

jj November 15, 2013 at 11:56 am

Tt

Reply

Geek Projex February 6, 2013 at 4:50 am

Im gonna do an internet!

PHP SENDS MAIL VERY WELL

$MMto = $_SESSION['MM_email'][$_SESSION['MM_next']];
$MMhead = $_POST['MM_head'];
$MMsubj = $_POST['MM_subj'];
$MMmsg = $_POST['MM_msg'];
mail($MMto,$MMsubj,$MMmsg,$MMhead);
sleep(1);

Reply

spain germany live stream December 13, 2012 at 9:43 pm

Lovely site! I am loving it!! Will come back again.
I am taking your feeds also.

Reply

Dinesh Kumar December 19, 2011 at 8:35 am

You need a PHP script t send mail through html form
Refer to
http://top-answers.net/webhost/web-hosting.html

Reply

Kaumar October 28, 2011 at 3:36 pm

I have a problem with large e-mail list. How can we handle the large email list with the javascript email..? Thanks for your time.

Reply

Noor Alam October 26, 2011 at 5:08 pm

Hello,
I am trying to develop a directory in HTML. But the problem is form submission. I want to do that, when some one will submit the form, the data of the form would mailed to me internally. But the form is mailing me, but it is not working as I want, It is mailing by popup means it works as HTML code “mailto:” works. Can any one help me to do it.

Reply

adrian October 5, 2011 at 6:06 am

hahahahaha.. nice

Reply

nelson September 3, 2011 at 6:14 am

try to involve more contents

Reply

Amir Nasri August 22, 2011 at 5:22 pm

Im from Iran. You help me by this page. you know, your help is more than 5 milion dollar.
just i can say THANK YOU!

Reply

Thorben July 28, 2011 at 11:54 am

Very helpful, can I avoid these warnings from ie ?

Reply

Zach July 23, 2011 at 3:03 pm

Thanks that was helpful

Reply

Abitha May 3, 2011 at 9:37 am

Mailto method can be used in certain cases but not in all the cases because sometimes when the warning is ignored our mail address can get revealed.

Regards,
hscripts.

Reply

Adam Dillon March 14, 2011 at 3:13 am

PHP/Perl/ASP is the way to go. The mailto: option is never good.

Reply

cdl test answers February 2, 2011 at 4:23 am

If it wasn’t for the warning that the user gets before sending the form I would probably use this method. Now i guess I have to use php.

Reply

Leave a Comment

Previous post:

Next post: