如何在html⽹页中提交表单直接发送到邮箱
如何在html⽹页中提交表单直接发送到邮箱?此问题⼀直困扰了我很久很久,后来了解到jmail组件可以解决此问题,⽽且现在的付费空间基本都会有此组件。分别建⽴表单页和asp页⾯,提交表单后通过asp页⾯调⽤jmail组件,实现将表单内容发送到指定邮箱的效果。
具体实现⽅法:
1.制作⼀个表单页⾯form.html(或修改⾃⼰⽹站上的表单页⾯,因为接下来与*.asp⽂件进⾏数据传递,所以对应的参数⼀定要写
对),name="form" method="post" action="s.asp
2.制作⼀个s.asp页⾯
3.让这两个⽂件上传到空间的形同路径下就可以实现提交表单后,表单内容⾃动发送到指定的邮箱,相应的会出现下⾯的页⾯
4.form.html对应的代码如下(将下⾯的代码复制后粘贴到记事本中,保存为form.html):
<body>
<form id="form" name="form" method="post" action="s.asp">
<table width="550" border="1" align="center">
<tr>
<td width="183" align="right" valign="top">Company:</td>
<td width="401"><label>
<input name="company" type="text" id="company" maxlength="25" />
</label></td>
</tr>
<tr>
<td align="right" valign="top">Website:</td>
<td><label>
<input name="website" type="text" id="website" value="" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">First name:</span></td>
<td><label>
<input name="fname" type="text" id="fname" maxlength="15" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">Last name:</span></td>
<td><label>
<input name="lname" type="text" id="lname" maxlength="15" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">Email address:</span></td>
<td><label>
<input name="email" type="text" id="email" maxlength="20" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">Phone:</span></td>
<td><label>
<input name="phone" type="text" id="phone" maxlength="20" />
</label></td>
</tr>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">Country:</span></td>
<td><label>
<input name="country" type="text" id="country" maxlength="15" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">City / Locality:</span></td>      <td><label>
<input name="city" type="text" id="city" maxlength="15" />
</label></td>
</tr>
<tr>
<td align="right" valign="top"><span class="STYLE39 STYLE42">Message:</span></td>
<td><label>
<textarea name="message" cols="55" rows="10" id="message"></textarea>
</label></td>
</tr>
<tr>
<td colspan="2" align="center" valign="top"><label>
<input name="submit" type="submit" id="submit" value="submit" />
</label>
<label>
<input name="reset" type="reset" id="reset" value="reset" />
</label></td>
</tr>
</table>
</form>
</body>
</html>
5.s.asp对应的代码如下(将下⾯的代码复制后粘贴到记事本中,保存为s.asp):
<html>
<head>
<title>send to your email</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Jmail" content="use jmail send to your email">
<meta name="send to your email" content="use jmail send to your email">
<title>send to your email</title>
</head>
网页colspan
<body>
<%
'下⾯是定义⼀些变量,是这些变量从表单页⾯获取信息
company=Request.Form ("company")
website=Request.Form ("website")
fname=Request.Form ("fname")
lname=Request.Form ("lname")
email=Request.Form ("email")
phone=Request.Form ("phone")
country=Request.Form ("country")
city=Request.Form ("city")
message=Request.Form ("message")
' 下⾯就是调⽤从表单页获取的信息,赋值到mess,&是连接符,vbcrlf表⽰换⾏回车:
mess = mess & "---------------Webmail表单开始-------------------" & vbcrlf
mess = mess & "Company:" & company & vbcrlf
mess = mess & "Website:" & website & vbcrlf
mess = mess & "First name:" & fname & vbcrlf
mess = mess & "Last name:" & lname & vbcrlf
mess = mess & "Email address:" & email & vbcrlf
mess = mess & "Phone:" & phone & vbcrlf
mess = mess & "Country:" & country & vbcrlf
mess = mess & "City / Locality:" & city & vbcrlf
mess = mess & "Message:" & message & vbcrlf
mess = mess & "---------------Webmail表单结束-------------------" & vbcrlf
' 下⾯是调⽤Jmail组件的部分,其中邮箱,密码填写正确的,否则发送不成功
Set JMail=Server.CreateObject("JMail.Message")
JMail.silent = true                '则errorcode包含的是错误代码
JMail.Logging=True                '是否使⽤⽇志
JMail.Charset="gb2312"
JMail.ContentType = "text/plain"      'text/html是超⽂本格式text/plain是⽂本格式
JMail.MailServerUserName = "" '您的邮件登录名
JMail.MailServerPassword = "123654"        '登录密码
JMail.From = ""                  '发件⼈(要填合法正确邮箱才能发出去信件)
JMail.FromName = "gewell"                '发件⼈姓名,引号内的内容可以修改为符合⾃⼰的信息JMail.AddRecipient ""      '收件⼈
JMail.Subject = "WebMail"      '主题,引号内的内容可以修改为⾃⼰认为合适的主题
JMail.Body = mess    '正⽂,通过使⽤前⾯的mess调⽤获取到得表单信息
JMail.Send "smtp.163"                        'smtp地址
JMail.Priority=3                              '1: 最⾼优先级.2:⾼ 3:普通 4:低 5:最低
Set JMail=nothing
%>
<CENTER>
Success ,Congratulation
</CENTER>
<p align="center">--- < <a href="index.htm">Go back to your website </a>> ---</p> </body>
</html>
6.将两个⽂件上传到空间中的相同路径,就可以了
可能此代码对于很多⼤虾来说太⼩⼉科了,希望能对刚⼊门的朋友有些帮助

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。