
hi...all of u.....i am work in jsp..i m new developer...i have create a my company website... than i have one problem...frnd how to send a contact form detail mail on a click submit button in jsp...pls help me.... this is my html page....
<html>
<head>
<title>Mail API</title>
</head>
<body>
<table border="1" width="50%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<form method="POST" action="mail.jsp">
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%"><b>To:</b></td>
<td width="100%"><input type="text" name="to" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Form:</b></td>
<td width="100%"><input type="text" name="from" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Subject:</b></td>
<td width="100%"><input type="text" name="subject" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Name:</b></td>
<td width="100%"><input type="text" name="name" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Email:</b></td>
<td width="100%"><input type="text" name="email" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Phone:</b></td>
<td width="100%"><input type="text" name="phone" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Description:</b></td>
<td width="100%"><textarea name="description" type="text"
cols="40" rows="5" size=80>
</textarea>
</td>
</tr>
<tr>
<td><p><input type="submit" value="Send Mail" name="sendMail"></td>
</tr>
</table>
</p>
</form>
</td>
</tr>
</table>
</body>
</html>
and this is my jsp page....
<%@ page language="java" import="javax.naming.*,java.io.*,javax.mail.*,
javax.mail.internet.*,com.sun.mail.smtp.*"%>Ok
<html>
<head>
<title>Mail</title>
</head>
<body>
<%
try{
Session mailSession = Session.getInstance(System.getProperties());
Transport transport = new SMTPTransport(mailSession,new URLName("localhost"));
transport.connect("localhost",25,null,null);
MimeMessage m = new MimeMessage(mailSession);
m.setFrom(new InternetAddress(%><%request.getParameter("from")%><%));
Address[] toAddr = new InternetAddress[] {
new InternetAddress(%><%request.getParameter("to")%><%)
};
m.setRecipients(javax.mail.Message.RecipientType.TO, toAddr );
m.setSubject(%><%request.getParameter("subject")%><%);
m.setSentDate(new java.util.Date());
m.setContent(%><%request.getParameter("description")%><%, "text/plain");
m.setContent(%><%request.getParameter("name")%><%, "text/plain");
m.setContent(%><%request.getParameter("email")%><%, "text/plain");
m.setContent(%><%request.getParameter("phone")%><%, "text/plain");
transport.sendMessage(m,m.getAllRecipients());
transport.close();
out.println("Thanks for sending mail!");
}
catch(Exception e){
out.println(e.getMessage());
e.printStackTrace();
}
%>
</body>
</html
> Blockquote
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.