This is a discussion on How can we send mail using JavaScript? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; How can we send mail using JavaScript?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi Sabari, 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!
__________________ J.Vijayanand |
| |||
| <html> <head> <title>Untitled</title> <script type="text/javascript"> function sendmail(_frm) { var eml="you@youraddress.com"; var bod="&body="+_frm.selOne.value+" ¦¦ "+_frm.txtOne.value; var subj="?subject=Whatever you want"; location.href="mailto:"+eml+subj+bod; } </script> </head> <body> <form action="mailto:you@youraddress.com" enctype="text/plain" method="POST" onsubmit="sendmail(this);return false;"> <select name="selOne"> <option value="Dog">Dog</option> <option value="Cat">Cat</option> </select> <textarea name="txtOne"></textarea> <input type="submit" value="Submit" /> </form> </body> </html> |
| |||
| Hence javascript cant directly send the mail, we can use "MAILTO" option. 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. ![]() 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. PHP Code: 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
__________________ J.Vijayanand |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to send mail with multiple attachments? | poornima | ASP and ASP.NET Programming | 5 | 02-01-2008 03:07 AM |
| How can we send mail using JavaScript? | sundarraja | PHP Programming | 2 | 01-22-2008 03:57 AM |
| How to Send mail using dot net ...? | a.deeban | ASP and ASP.NET Programming | 9 | 01-17-2008 09:20 PM |
| How to send data from servlet to javascript variables | Pvinothkumar | HTML, CSS and Javascript Coding Techniques | 0 | 10-09-2007 11:05 PM |
| How to Send Mail Using Stored Procedure in MS SQL SERVER 200x?? | Gopisoft | Database Support | 1 | 07-17-2007 09:43 AM |