最经典的在线咨询表单
第一个文件,提交表单页面,可以是静态的,选了些常用的字段,代码如下:
<form name="form1" action="tj.asp" method="post">
<table width="500" align="center" border="0">
<tr height="30"><td width="135">姓 名:</td><td><input type="text" name="name"></td><td><font color="red">*</font> 您的姓名</td></tr>
<tr height="30"><td>手 机:</td><td><input type="text" name="mobile"></td><td><font color="red">*</font> 确保及时联系到您</td></tr>
<tr height="30"><td>座 机:</td><td><input type="text" name="tel"></td><td> <font color="red">*</font> 与您联系时节约您的话费</td></tr>
<tr height="30"><td>传 真:</td><td><input type="text" name="fax"></td><td> <font color="red">*</font> 及时传递相关资料</td></tr>
<tr height="30"><td>电子邮箱邮箱:</td><td><input type="text" name="email"></td><td><font color="red">*</font> 及时邮寄相关资料</td></tr>
<tr height="30"><td>详细地址:</td><td><input type="text" name="address"></td><td> <font color="red">*</font> 及时邮寄相关资料</td></tr>
<tr height="30"><td>邮 编:</td><td><input type="text" name="postcode"></td><td> <font color="red">*</font> 及时邮寄相关资料</td></tr>
<tr height="30"><td valign="top">留言内容:</td><td><textarea name="content" style="height:140px;"></textarea></td>
<td valign="top"><font color="red">*</font> 请附上你咨询的详细内容,我们收到后会马上处理!谢谢您的支持!</td></tr>
<tr height="40"><td colspan="3" align="center"><input type="button" value="确 定" onclick="check()"> <input type="reset" VALUE="清 空"></td></tr>
</table>
</form>
加上一个js验证,代码:
<script LANGUAGE="JavaScript">
function check()
{
if (document.Form1.name.value=="")
{
alert("请填写联系人")
document.Form1.name.focus()
document.Form1.name.select()
return
}
if (document.Form1.mobile.value=="")
{
alert("请填写手机")
document.Form1.mobile.focus()
document.Form1.mobile.select()
return
}
if (document.Form1.tel.value=="")
{
alert("请填写座机")
document.Form1.tel.focus()
document.Form1.tel.select()
return
}
if (document.Form1.fax.value=="")
{
alert("请填写传真")
document.Form1.fax.focus()
document.Form1.fax.select()
return
}
if (document.Form1.email.value=="")
{
alert("请填写电子邮件")
document.Form1.email.focus()
document.Form1.email.select()
return
}
if (document.Form1.address.value=="")
{
alert("请填写联系地址")
document.Form1.address.focus()
document.Form1.address.select()
return
}
if (document.Form1.postcode.value=="")
{
alert("请填写邮政编码")
document.Form1.postcode.focus()
document.Form1.postcode.select()
return
}
if (document.Form1.content.value=="")
{
alert("反馈信息不能为空")
document.Form1.content.focus()
document.Form1.content.select()
return
}
document.Form1.submit()
}
</SCRIPT>
第二个页面,表单处理发送页面:
<%
dim name
dim mobile
dim tel
dim fax
dim email
dim address
dim postcode
dim content
name=request("name")
mobile=request("mobile")
tel=request("tel")
fax=request("fax")
email=request("email")
address=request("address")
postcode=request("postcode")
content=request("content")
umail="xxx@xxx.com" '你接收信息的邮箱
if (name="" or mobile="" or tel="" or fax="" or email="" or address="" or postcode="" or content="") then
response.write "<br>必填项目不全,请勿从外部递交数据。"
response.end
elseif IsValidEmail(email) then
else
response.write "<br>email地址不正确。"
response.end
end if
topic="咨询"
mailbody="<div style='height:22px;line-height:22px; padding:3px 0 0 8px; background:#E6E6E6; font-weight:bold; margin:5px 10px;' align='center'><font color='red'>咨询信息</font></div><table width='500' align='center' border='0'><tr height='30'><td width='135'>姓 名:</td><td>"&name&"</td><tr height='30'><td>手 机:</td><td>"&mobile&"</td></tr><tr height='30'><td>座 机:</td><td>"&tel&"</td></tr><tr height='30'><td>传 真:</td><td>"&fax&"</td></tr><tr height='30'><td>电子邮箱:</td><td>"&email&"</td></tr><tr height='30'><td>详细地址:</td><td>"&address&"</td></tr><tr height='30'><td>邮 编:</td><td>"&postcode&"</td></tr><tr height='30'><td valign='top'>留言内容:</td><td>"&content&"</td></tr></table>"
dim JMail
Set JMail=Server.CreateObject("JMail.Message")
JMail.silent = true
JMail.Logging=True
JMail.Charset="gb2312"
JMail.ContentType = "text/html"
JMail.From="webmaster@xxx.com" '从哪里发信,一定要和下面对应,要不然就发不了信
JMail.FromName=name
JMail.Subject=topic
JMail.Body=mailbody
JMail.AddRecipient umail
JMail.Priority=1
JMail.Maildomain = "smtp.mail.sogou.com" 'smtp服务器souhu的免费企业邮箱
JMail.MailServerUserName = "webmaster@xxx.com" '您的邮件服务器登录名xxx.com就是你申请的域名
JMail.MailServerPassword = "password" '登录密码
JMail.Send("smtp.mail.sogou.com ") 'smtp服务器
Set JMail=nothing
response.write "<center><br>已经提交咨询。我们会马上处理您的问题,谢谢支持!<br><br><a href=http://www.mmxx8.com>返回首页</a></center>"
function IsValidEmail(email)
dim names, name, i, c
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
end function
%>
</td>
</tr>
</table>
搞定了,非常经典,这个可以做n个变换,比如做一个友情链接的在线申请,嘿嘿!
jmail组件网上找找,很多。
- 相关文章
- 对于表单验证和表单内容过滤的研究 - 2007-12-20
- 关于sablog的表单验证 - 2007-01-11











