Dear Sir,
with your help i have written code for email. attached is a code for your consideration and modification.
problem are as under-
1. in subject section i have formatting problem,as it is appearing in a row. can it possible to let appear the content of subject to user as it is being written in asp's textbooks?
2. function checkform() is not working. It is not throwing any error ,it also prevent to appear invalid email address (say missing @ or so)to appear in from section. but not stopping wrong entry in page,neither alert "alert("Email address is not valid.");" is getting invoked?
3. Can code be modified to get return receipt to user stating some text.?
your help in this regard will be highly appreciated.
regards
om prakash
[code]
<%@ Language=VBScript %>
<% option explicit %>
<HTML>
<HEAD>
<%
dim sqlstr,recset,vto,vfrom,vsubject,vcc,vbcc,vmessage ,sqlstr1,recset1,vname
dim conn,ObjCom
%>
<script language="javascript">
function fn_submit()
{
if (document.forms[0].txtName.value==null || document.forms[0].txtName.value=="" )
{
alert ("Name is empty");
document.forms[0].txtName.focus();
return false;
}
else if (document.forms[0].vendorcode.value==null || document.forms[0].vendorcode.value=="")
{
alert ("IFFCO Vendor Code is empty");
document.forms[0].vendorcode.focus();
return false;
}
else if (document.forms[0].txtemail.value==null || document.forms[0].txtemail.value=="")
{
alert ("Email address is empty");
document.forms[0].txtemail.focus();
return false;
}
else
{
document.forms[0].submit();
}
}
function validemail(email) {
invalidChars = " /:"
if (email == "") {
return (false);
}
for (i=0; i < invalidChars.length; i++) {
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) != -1)
{
return (false);
}
}
atPos = email.indexOf("@", 1)
if (atPos == -1) {
return (false);
}
periodPos = email.indexOf(".", atPos)
if (periodPos == -1) {
return (false);
}
if (periodPos + 3 > email.length) {
return (false);
}
else
return (true);
}
function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
function checkform() {
if (!validemail(document.frmSendEmail.txtemail.value) ) {
alert("Email address is not valid.");
document.frmSendEmail.txtemail.focus();
return false;
}
}
</script>
<%
If Request.Form("IsSubmitted") <> "" Then
set conn= server.createobject("ADODB.Connection")
conn.ConnectionString = Session("eproc_ConnectionString")
conn.Open
'on error resume next
' if err.number <> 0 then
sqlstr = "select e_mail,e_mail_contact from punitmas where ltrim(rtrim(unit_cd))in(" & session("unit_code")& ")"
sqlstr1 ="select vend_cd,name from PVENDOR where vend_cd = '"& Request.Form("vendorcode") &"'"
set recset=server.CreateObject("ADODB.Recordset")
recset.open sqlstr,conn
if recset.eof and recset.bof then
Response.Write("No Email Address found")
else
recset.MoveFirst
while Not recset.eof
vto = "
[email protected],"& recset.Fields("e_mail") &","& recset.Fields("e_mail_contact")
recset.MoveNext
wend
end if
' This loop finds name of Vendor
set recset1=server.CreateObject("ADODB.Recordset")
recset1.open sqlstr1,conn
if recset1.eof and recset1.bof then
vname = "Appears to be Anauthorised person .....please veryfy .."
else
recset1.MoveFirst
while Not recset1.eof
vname = recset1.Fields("name")
recset1.MoveNext
wend
end if
Dim UserName
Dim UserMessage
UserName = Request.Form("txtName")
UserMessage = Request.Form("txtMessage")
Dim Message
'Message = "Mail from the Web site" & vbCrlf & vbCrLf
'Message = Message & "User " & UserName & _
' " left the following message: " & vbCrLf
'Message = Message & UserMessage & vbCrLf & vbCrLf
Message = "This Password Reset Request is for unit "& session("topname")
Message = Message & "Vendor Code = "& Request.Form("vendorcode")& "Vendor's Name = "& vname
Message = Message & UserMessage
Const cdoSendUsingPort = 2
Dim oConfiguration
Dim oMessage
Dim oFields
Set oMessage = CreateObject("CDO.Message")
Set oConfiguration = CreateObject("CDO.Configuration")
Set oFields = oConfiguration.Fields
With oFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
= cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "xx.12.1.1"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=100
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
= 10
'for priority
.Item("urn:schemas:mailheader:X-MSMail-Priority") = 0
'for return receipt
'.fields("urn:schemas:mailheader:disposition-notification-to") = "
[email protected]" 'ToDo: Type a valid e-mail address.
'.fields("urn:schemas:mailheader:return-receipt-to") = "
[email protected]" 'ToDo: Type a valid e-mail address.
'.DSNOptions = cdoDSNSuccessFailOrDelay
'.DSNOptions = 14
.Update
End With
'Apply the settings to the message.
With oMessage
Set .Configuration = oConfiguration
.To = vto
.Bcc = vbcc
.From = Request.Form("txtemail")
.Subject = "User " & UserName & " left a message"
.HTMLBody = Message
.Send
End With
'Clean up variables.
Set oMessage = Nothing
Set oConfiguration = Nothing
Set oFields = Nothing
Response.Redirect("ThankYou.asp")
conn.Close
set conn = nothing
End If
%>
</HEAD>
<BODY>
<form id="frmSendEmail" name="frmSendEmail" method="post" action="Sendemail.asp" onsubmit="javascript
:return checkform();">
<table border = "0" align ="top" cellspacing = 1 cellpadding = 1>
<tr><td ALIGN=center>Password Reset Requsition From </td></tr>
<tr><td align=left><b>To prevent abuse, your IP Address (<%= Request.ServerVariables("http_host")%>)will be</td></tr>
<p><tr><td align=left><b> logged and recorded for this email message.</b></td></tr></P>
<tr></tr>
<tr bgcolor="#eeeeee">
<td ALIGN=left><STRONG>Your
Name:</STRONG> & nbsp;
<input name="txtName" id="txtName" style="WIDTH: 206px; HEIGHT: 22px" size=26
> * </td><tr>
<tr bgcolor="#eeeeee">
<td ALIGN=left><STRONG>Your Vendor Code:</STRONG> <INPUT id=vendorcode name=vendorcode
style="WIDTH: 83px; HEIGHT: 22px" size=10 onkeypress="uppercase();" maxlength = "6"> *</td></tr>
<tr bgcolor="#eeeeee">
<td ALIGN=left><STRONG>Your Company
email:</STRONG> <INPUT id=txtemail style="LEFT: 95px; WIDTH: 208px; TOP: 40px; HEIGHT: 22px" size=25
name=txtemail> *</td>
<td ALIGN=left>(On Which you wanted to receive your password)</td></tr>
<tr bgcolor="#eeeeee">
<td ALIGN=left><STRONG>Your message:</STRONG> </td></tr>
<tr bgcolor="#eeeeee">
<td align = left><TEXTAREA id=txtMessage name=txtMessage rows=10 cols=40></TEXTAREA></td></tr><br>
<tr bgcolor="#eeeeee"><td><input type="button" name="btnSubmit" id="btnSubmit"
value="Send Message" onclick="fn_submit()" > </td></tr>
<tr bgcolor="white"><td align = middle><p><A href="JavaScript
:onClick=window.close()">Close Window</a></p>
</td></tr>
</table>
<input type="hidden" value= "True" name="IsSubmitted" >
</form>
</BODY>
</HTML>
[code]
om prakash kumar