text/html 的Email发送例子

14 篇文章 0 订阅

<%

Set msg = Server.CreateObject("JMail.Message")
msg.silent = true
msg.Logging = true
msg.Charset = "gb2312"'中文编码
msg.ContentType = "text/html"'html模式
msg.MailServerUserName = "xxxx@xx.com" 'smtp用户名 
msg.MailServerPassword = "xxx"'smtp密码
msg.From = "xxx@xxx.com"'发送邮件者邮件地址
msg.FromName = "怎么可以这样对我"'发送邮件者姓名
msg.AddRecipient "xxx@xxx.com"'收件人地址
'msg.AddRecipient "xxx@xx.cn"'收件人地址'可以连续加入多个
msg.Subject = "酒店预订"'标题
'msgs="我晕倒"
strHTML = "<table width=""80%"" border=""1"">" &chr(13) &chr(10) '这里需要加上两个"
strHTML = strHTML & " <tr>" &chr(13) &chr(10) 'chr(13)硬回车chr(10)软回车
strHTML = strHTML & "<td align=""center"" valign=""middle"">HELLO~!</td>" &chr(13) &chr(10)
strHTML = strHTML & "</tr>" &chr(13) &chr(10)
strHTML = strHTML & "</table>"

msg.Body=strHTML'信体内容
msg.Send ("mail.hrcworldwide.com")  'smtp服务器地址
set msgs=nothing
response.write("邮件发送成功!"&"<a href=send_email1.asp></a>")
%>
<html>
<head>
<title>后台管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../css/css.css" type="text/css">
</head>
<%
function input(user_mail)
dim names, c
input = true
names = Split(user_mail, "@")
if UBound(names) <> 1 then
   input = false
   exit function
end if
for each name in names
   if Len(name) <= 0 then
     input = 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
       input = false
       exit function
     end if
   next
   if Left(name, 1) = "." or Right(name, 1) = "." then
      input = false
      exit function
   end if
next
if InStr(names(1), ".") <= 0 then
   input = false
   exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
   input = false
   exit function
end if
if InStr(email, "..") > 0 then
   input = false
end if
end function
%>
<%
   if request("action")="send" then
   if input(trim(request("email")))=false then
response.Write"<SCRIPT language=JavaScript>alert('Sorry,your E-mail is error。please check email format!');"
response.write"javascript:history.go(-1)</SCRIPT>"
founderr=true
response.End
end if
  if request("title")="" then
response.Write("<script language=javascript>alert('Please input title!');")
response.Write("javascript:history.go(-1)</script>")
response.End()
end if
  if request("body")="" then
response.Write("<script language=javascript>alert('Please input email body!');")
response.Write("javascript:history.go(-1)</script>")
response.End()
end if
  if request("name1")="" then
response.Write("<script language=javascript>alert('Please input your name!');")
response.Write("javascript:history.go(-1)</script>")
response.End()
end if
 '==========================以下绿色代码是判断服务器是否支持JMAIL组件
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
if not IsObjInstalled("JMail.Message") then
Response.write"你所使用的服务器不支持邮件发送!"
Response.End
end if
'==========================================================
'if Trim(Request.Form("action")) = "send" then
SmtpServer = "smtp.21cn.com"'邮箱系统服务器地址
FromUserEmail = "xxx@xx.com"'Request.Form("FromUserEmail")'发件人邮箱地址
FromUser = "bellling3"'Request.Form("FromUser")'发件人姓名
ForUserEmail = request("email")'"xxx@xxx.com"'收件人邮箱地址
FromUserID = "xxx@xx.com"'Request.Form("FromUserID")'发件人用户名
FromUserIDPW = "xxx"'Request.Form("FromUserIDPW")'发件人密码
Dim JMail
Set JMail=Server.CreateObject("JMail.Message")
JMail.silent = true
JMail.Logging=True
JMail.Charset="gb2312"
JMail.ContentType = "text"
JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
'if Request.Form("smtpPW") = "1" then '判断服务器是否需要身份验证
' 身份验证
JMail.MailServerUserName = FromUserID
' 身份验证的用户名
JMail.MailServerPassword = FromUserIDPW
' 身份验证的密码
'end if
JMail.From = FromUserEmail '发件人的信箱
JMail.FromName = FromUser '发件人的名字
title=request("title")
JMail.Subject = title '邮件的主题
content=request("body")
JMail.Body = content '邮件的内容
'==============================收件人的地址!
JMail.AddRecipient(ForUserEmail) '收件人的地址
JMail.Priority=5 '邮件级别1-5数字越大级别越高---3为普通邮件
JMail.Send(SmtpServer) '红色变量是邮件服务器地址
JMail.Close
Set JMail=nothing
'if err then
'err.clear
'Response.Write "<center><b> 发信功能已经打开,但因服务器不支持发信或者信箱地址错误,导致信件无法发出!</b></center>"
'Response.End
'else
'Response.End
'end if
  response.write("<script language='javascript'>")
  response.write("window.alert('邮件发送成功!!');")
  response.write("window.close();")
  response.write("</script>")
end if

 %>
<body bgcolor="#99CCFF">
<form action="?action=send" method="post" name="form1">
  <br>
  <table border="0" cellspacing="1" cellpadding="2" bgcolor="#FFFFFF" width="98%" align="center">
    <tr>
      <td colspan="3"  bgcolor="#B0CBE6"><div align="center"></div>
        <div align="center">邮件发送</div></td>
    </tr>
    <tr>
      <td colspan="3" bgcolor="#D1E1F1">&nbsp;</td>
    </tr>
    <tr>
      <td width="28%" bgcolor="#D1E1F1">&nbsp;</td>
      <td width="9%" bgcolor="#D1E1F1">收件人 </td>
      <td width="63%" bgcolor="#D1E1F1"><input name="email" type="text" id="email" size="40" value="<%=request("mail")%>"></td>
    </tr>
    <tr>
      <td bgcolor="#D1E1F1">&nbsp;</td>
      <td bgcolor="#D1E1F1">标题</td>
      <td bgcolor="#D1E1F1"><input name="title" type="text" id="title" size="40"></td>
    </tr>
     <tr>
      <td bgcolor="#D1E1F1">&nbsp;</td>
      <td bgcolor="#D1E1F1">你的姓名</td>
      <td bgcolor="#D1E1F1"><input name="name1" type="text" id="name1" size="40"></td>
    </tr>
    <tr>
      <td colspan="3" bgcolor="#D1E1F1"><div align="center">内容</div></td>
    </tr>
    <tr>
      <td colspan="3" bgcolor="#D1E1F1"><div align="center">
          <textarea name="body" cols="70" rows="9" id="body"></textarea>
        </div></td>
    </tr>
    <tr>
      <td height="35" colspan="3" valign="top" bgcolor="#D1E1F1"><div align="center">
          <input type="submit" name="Submit" value="发送">
          <input type="reset" name="Submit2" value="重置">
        </div></td>
    </tr>
  </table>
</form>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值