主题:表单提交Jmail发信脚本求高手解答!
大家好,我是一菜鸟,想在我的网页上加一个表单提交发送到email的功能,想到了用ASP Jmail来实现。我用forms to go这个软件生成了一个asp文件,但是不行。
提交表单后的错误提示为:JMail reported an error sending the email. Error: Form submitted successfully. It will be reviewed soon.
总之死活都收不到邮件,跪求哪位高手帮忙看看那里有问题,最好能解释修改下。提前多谢了!脚本如下:
<%
CONST kOptional = true
CONST kMandatory = false
'====================================================
' Function: FilterControlChars =
'====================================================
Function FilterCchar(TextToFilter)
Dim regEx
Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = true
regEx.Pattern ="[\x00-\x1F]"
filterCchar = regEx.Replace(TextToFilter, "")
End Function
'====================================================
' Function: SQLQuoteReplace =
'====================================================
Function SQLQuoteReplace(FieldValue)
SQLQuoteReplace = Replace(FieldValue, "'", "''")
End Function
'====================================================
' Function: ValidateEmail =
'====================================================
Function check_email(Email, isOpt)
Dim regEx, retVal
check_email = false
If ( (Len(Email) = 0) and (isOpt = kOptional) ) Then
check_email = true
Else
Set regEx = New RegExp
regEx.Pattern ="^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$"
regEx.IgnoreCase = true
retVal = regEx.Test(Email)
If retVal Then
check_email = true
End If
End If
End Function
'====================================================
' Function: ShowDate =
'====================================================
Function ShowDate(ftgdf)
Dim FTGNow, FTGDay, FTGMonth, FTGYearS, FTGYearL, FTGHour, FTGMinute, FTGSecond, AMPM
FTGNow = Now
FTGDay = CStr(Day(FTGNow))
FTGMonth = CStr(Month(FTGNow))
FTGYearS = Right(CStr(Year(FTGNow)), 2)
FTGYearL = CStr(Year(FTGNow))
FTGHour = CStr(Hour(FTGNow))
FTGMinute = CStr(Minute(FTGNow))
FTGSecond = CStr(Second(FTGNow))
If FTGDay < 10 Then FTGDay = "0" & FTGDay
If FTGMonth < 10 Then FTGMonth = "0" & FTGMonth
If FTGHour < 10 Then FTGHour = "0" & FTGHour
If FTGMinute < 10 Then FTGMinute = "0" & FTGMinute
If FTGSecond < 10 Then FTGSecond = "0" & FTGSecond
If ftgdf = 1 Then ShowDate = FTGMonth & "/" & FTGDay & "/" & FTGYearS
If ftgdf = 2 Then ShowDate = FTGDay & "/" & FTGMonth & "/" & FTGYearS
If ftgdf = 3 Then ShowDate = FTGDay & "/" & FTGMonth & "/" & FTGYearL
If ftgdf = 4 Then ShowDate = FTGYearL & "-" & FTGMonth & "-" & FTGDay
If ftgdf = 6 Then ShowDate = FTGHour & ":" & FTGMinute & ":" & FTGSecond
If ftgdf = 7 Then ShowDate = FTGYearL & "-" & FTGMonth & "-" & FTGDay & " " & FTGHour & ":" & FTGMinute & ":" & FTGSecond
If ftgdf = 5 Then
AMPM = "AM"
FTGHour = Hour(FTGNow)
If FTGHour > 12 Then
FTGHour = FTGHour - 12
AMPM = "PM"
If FTGHour < 10 Then FTGHour = "0" & FTGHour
ElseIf FTGHour = 12 Then
AMPM = "PM"
ElseIf FTGHour < 10 Then
FTGHour = "0" & FTGHour
End If
ShowDate = FTGHour & ":" & FTGMinute & ":" & FTGSecond & " " & AMPM
End If
End Function
Dim ClientIP
if Request.ServerVariables("HTTP_X_FORWARDED_FOR") <> "" then
ClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
else
ClientIP = Request.ServerVariables("REMOTE_ADDR")
end if
Dim JMail
FTGDate = request.form("Date")
FTGTime = request.form("Time")
FTGPartySize = request.form("PartySize")
FTGTitle = request.form("Title")
FTGName = request.form("Name")
FTGEmail = request.form("Email")
FTGRepeatEmail = request.form("RepeatEmail")
FTGPhone = request.form("Phone")
FTGRequests = request.form("Requests")
FTGReserve = request.form("Reserve")
FTGreset = request.form("reset")
' Fields Validations
validationFailed = false
Dim FTGErrorMessage
Set FTGErrorMessage = Server.CreateObject("Scripting.Dictionary")
If (not check_email(FTGEmail, kMandatory)) Then
validationFailed = true
FTGErrorMessage.Add "Email", "invalid email"
End If
'====================================================
' Code: ErrorMessage =
'====================================================
If (validationFailed = true) Then
ErrorPage = "<html><head><meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" /><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>"
dictItems = FTGErrorMessage.Items
For cnt = 0 To FTGErrorMessage.Count - 1
ErrorList = ErrorList & dictItems( cnt ) & "<br />"
Next
ErrorPage = Replace(ErrorPage, "<!--VALIDATIONERROR-->", ErrorList)
Response.Write ErrorPage
Response.End
End If
emailSubject = FilterCchar("BOOKING")
emailBodyText = "Date : " & FTGDate & "" & vbCrLf _
& "Time : " & FTGTime & "" & vbCrLf _
& "Party Size : " & FTGPartySize & "" & vbCrLf _
& "Title : " & FTGTitle & "" & vbCrLf _
& "Name : " & FTGName & "" & vbCrLf _
& "Email : " & FTGEmail & "" & vbCrLf _
& "Phone : " & FTGPhone & "" & vbCrLf _
& "Requests : " & FTGRequests & "" & vbCrLf _
& "" & vbCrLf _
& ""
' Owner Email: JMail
Set JMail = Server.CreateObject("JMail.Message")
emailFromName = FilterCchar(FTGName)
emailFrom = FilterCchar(FTGEmail)
JMail.FromName = emailFromName
JMail.From = emailFrom
JMail.AddRecipient "收信人Email地址", "收信人"
JMail.Subject = emailSubject
JMail.HtmlBody = emailBodyText
JMail.Body = emailBodyText
JMail.Charset = "gb2312"
Jmail.MailServerUserName = "登录用户名"
Jmail.MailServerPassWord = "登录密码"
JMail.MailDomain = "域名" '如果用"name@domain.com"这样的用户名登录时,请指明domain.com
JMail.ContentType = "text/html"
JMail.silent = True
JMail.Priority = "1"
On Error Resume Next
JMail.Send("SMTP服务器地址")
If JMail.ErrorCode > 0 then
Response.Write "JMail reported an error sending the email. Error: " & Err.Description
End If
'====================================================
' Code: SuccessMessage =
'====================================================
SuccessPage = "<html><head><meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" /><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>"
Response.Write SuccessPage
%>
提交表单后的错误提示为:JMail reported an error sending the email. Error: Form submitted successfully. It will be reviewed soon.
总之死活都收不到邮件,跪求哪位高手帮忙看看那里有问题,最好能解释修改下。提前多谢了!脚本如下:
<%
CONST kOptional = true
CONST kMandatory = false
'====================================================
' Function: FilterControlChars =
'====================================================
Function FilterCchar(TextToFilter)
Dim regEx
Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = true
regEx.Pattern ="[\x00-\x1F]"
filterCchar = regEx.Replace(TextToFilter, "")
End Function
'====================================================
' Function: SQLQuoteReplace =
'====================================================
Function SQLQuoteReplace(FieldValue)
SQLQuoteReplace = Replace(FieldValue, "'", "''")
End Function
'====================================================
' Function: ValidateEmail =
'====================================================
Function check_email(Email, isOpt)
Dim regEx, retVal
check_email = false
If ( (Len(Email) = 0) and (isOpt = kOptional) ) Then
check_email = true
Else
Set regEx = New RegExp
regEx.Pattern ="^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$"
regEx.IgnoreCase = true
retVal = regEx.Test(Email)
If retVal Then
check_email = true
End If
End If
End Function
'====================================================
' Function: ShowDate =
'====================================================
Function ShowDate(ftgdf)
Dim FTGNow, FTGDay, FTGMonth, FTGYearS, FTGYearL, FTGHour, FTGMinute, FTGSecond, AMPM
FTGNow = Now
FTGDay = CStr(Day(FTGNow))
FTGMonth = CStr(Month(FTGNow))
FTGYearS = Right(CStr(Year(FTGNow)), 2)
FTGYearL = CStr(Year(FTGNow))
FTGHour = CStr(Hour(FTGNow))
FTGMinute = CStr(Minute(FTGNow))
FTGSecond = CStr(Second(FTGNow))
If FTGDay < 10 Then FTGDay = "0" & FTGDay
If FTGMonth < 10 Then FTGMonth = "0" & FTGMonth
If FTGHour < 10 Then FTGHour = "0" & FTGHour
If FTGMinute < 10 Then FTGMinute = "0" & FTGMinute
If FTGSecond < 10 Then FTGSecond = "0" & FTGSecond
If ftgdf = 1 Then ShowDate = FTGMonth & "/" & FTGDay & "/" & FTGYearS
If ftgdf = 2 Then ShowDate = FTGDay & "/" & FTGMonth & "/" & FTGYearS
If ftgdf = 3 Then ShowDate = FTGDay & "/" & FTGMonth & "/" & FTGYearL
If ftgdf = 4 Then ShowDate = FTGYearL & "-" & FTGMonth & "-" & FTGDay
If ftgdf = 6 Then ShowDate = FTGHour & ":" & FTGMinute & ":" & FTGSecond
If ftgdf = 7 Then ShowDate = FTGYearL & "-" & FTGMonth & "-" & FTGDay & " " & FTGHour & ":" & FTGMinute & ":" & FTGSecond
If ftgdf = 5 Then
AMPM = "AM"
FTGHour = Hour(FTGNow)
If FTGHour > 12 Then
FTGHour = FTGHour - 12
AMPM = "PM"
If FTGHour < 10 Then FTGHour = "0" & FTGHour
ElseIf FTGHour = 12 Then
AMPM = "PM"
ElseIf FTGHour < 10 Then
FTGHour = "0" & FTGHour
End If
ShowDate = FTGHour & ":" & FTGMinute & ":" & FTGSecond & " " & AMPM
End If
End Function
Dim ClientIP
if Request.ServerVariables("HTTP_X_FORWARDED_FOR") <> "" then
ClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
else
ClientIP = Request.ServerVariables("REMOTE_ADDR")
end if
Dim JMail
FTGDate = request.form("Date")
FTGTime = request.form("Time")
FTGPartySize = request.form("PartySize")
FTGTitle = request.form("Title")
FTGName = request.form("Name")
FTGEmail = request.form("Email")
FTGRepeatEmail = request.form("RepeatEmail")
FTGPhone = request.form("Phone")
FTGRequests = request.form("Requests")
FTGReserve = request.form("Reserve")
FTGreset = request.form("reset")
' Fields Validations
validationFailed = false
Dim FTGErrorMessage
Set FTGErrorMessage = Server.CreateObject("Scripting.Dictionary")
If (not check_email(FTGEmail, kMandatory)) Then
validationFailed = true
FTGErrorMessage.Add "Email", "invalid email"
End If
'====================================================
' Code: ErrorMessage =
'====================================================
If (validationFailed = true) Then
ErrorPage = "<html><head><meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" /><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>"
dictItems = FTGErrorMessage.Items
For cnt = 0 To FTGErrorMessage.Count - 1
ErrorList = ErrorList & dictItems( cnt ) & "<br />"
Next
ErrorPage = Replace(ErrorPage, "<!--VALIDATIONERROR-->", ErrorList)
Response.Write ErrorPage
Response.End
End If
emailSubject = FilterCchar("BOOKING")
emailBodyText = "Date : " & FTGDate & "" & vbCrLf _
& "Time : " & FTGTime & "" & vbCrLf _
& "Party Size : " & FTGPartySize & "" & vbCrLf _
& "Title : " & FTGTitle & "" & vbCrLf _
& "Name : " & FTGName & "" & vbCrLf _
& "Email : " & FTGEmail & "" & vbCrLf _
& "Phone : " & FTGPhone & "" & vbCrLf _
& "Requests : " & FTGRequests & "" & vbCrLf _
& "" & vbCrLf _
& ""
' Owner Email: JMail
Set JMail = Server.CreateObject("JMail.Message")
emailFromName = FilterCchar(FTGName)
emailFrom = FilterCchar(FTGEmail)
JMail.FromName = emailFromName
JMail.From = emailFrom
JMail.AddRecipient "收信人Email地址", "收信人"
JMail.Subject = emailSubject
JMail.HtmlBody = emailBodyText
JMail.Body = emailBodyText
JMail.Charset = "gb2312"
Jmail.MailServerUserName = "登录用户名"
Jmail.MailServerPassWord = "登录密码"
JMail.MailDomain = "域名" '如果用"name@domain.com"这样的用户名登录时,请指明domain.com
JMail.ContentType = "text/html"
JMail.silent = True
JMail.Priority = "1"
On Error Resume Next
JMail.Send("SMTP服务器地址")
If JMail.ErrorCode > 0 then
Response.Write "JMail reported an error sending the email. Error: " & Err.Description
End If
'====================================================
' Code: SuccessMessage =
'====================================================
SuccessPage = "<html><head><meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" /><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>"
Response.Write SuccessPage
%>