IT Community - Software Programming, Web Development and Technical Support

How can we send mail using JavaScript?

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


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-11-2007, 10:02 AM
Sabari Sabari is offline
D-Web Genius
 
Join Date: Jul 2007
Posts: 1,008
Sabari is on a distinguished road
Default How can we send mail using JavaScript?

How can we send mail using JavaScript?
__________________
Thanks & Regards
Sabari...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-12-2007, 12:29 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: How can we send mail using JavaScript?

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-12-2007, 12:29 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How can we send mail using JavaScript?

<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>
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-12-2007, 12:33 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: How can we send mail using JavaScript?

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:
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
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 11:43 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0