简单的asp形式

时间:2012-07-29 14:56:40

标签: forms asp-classic contact-form

尝试在123-reg上获得一个非常简单的经典asp表单并运行。

123-reg提供了一个脚本来完成这项工作,但我不知道这个脚本是如何连接到我所做的那样。

这是我的html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<form id="form" target="_blank" action="script.asp" method="post">

Name: <input name="Name" type="text" /><br />
Customer ID: <input name="Customer ID" type="text" /><br />
Email Address: <input name="Email" type="text" /><br />
Comments:<br />
<textarea name="Comments" rows=5 cols=50></textarea>
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>

</body>
</html>

这是一个简单的脚本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Secure Mail (ASP)</title>

</head>
<body>
<div id="container" class="index" style="padding:10px">

<br />
<br />
<h2>Secure Mail (ASP)</h2>
<br />

<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'To get the script for work please set the following values:

'Set the credentials for your email account to send the email from
username="MYUSERNAME"     'Insert your email account username between the double quotes            
password="MYPASSWORD"     'Insert your email account password between the double quotes              

'Set the from and to email addresses
sendFrom = "admin@MYURL.co.uk"   'Insert the email address you wish to send from   
sendTo = "MYEMAIL"     'Insert the email address to send to in here

'DO NOT CHANGE ANY SCRIPT CODE BELOW THIS LINE.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This script demonstrates how to send an email using asmtp

'Create a CDO.Configuration object
Set objCdoCfg = Server.CreateObject("CDO.Configuration")

'Configure the settings needed to send an email
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="intmail.atlas.pipex.net"
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objCdoCfg.Fields.Update

'Create the email that we are going to send
Set objCdoMessage = Server.CreateObject("CDO.Message")
Set objCdoMessage.Configuration = objCdoCfg
objCdoMessage.From = sendFrom
objCdoMessage.To = sendTo
objCdoMessage.Subject = "This is a test email."

'Add the email body text
objCdoMessage.TextBody = "Email sent using ASMTP from a ASP script."


On Error Resume Next

'Send the email
objCdoMessage.Send

'Check if an exception was thrown       
If Err.Number <> 0 Then
    'Response.Write "<FONT color=""Red"">Error: " & Err.Description & " (" & Err.Number & ")</FONT><br/>"
Else
    Response.Write "<FONT color=""Green"">The email has been sent to " & sendTo & ".</FONT>"
End If

'Dispose of the objects after we have used them
Set objCdoMessage = Nothing
Set objCdoCfg = Nothing
Set FSO = nothing
Set TextStream = Nothing
%>


</div>
</body> 
</html>

我知道脚本在发送电子邮件时有效,但HTML表单中包含的信息似乎都没有包含在内。

通常不与表格一起工作,所以会感激地收到任何建议。

谢谢,

1 个答案:

答案 0 :(得分:0)

您在asp中没有请求将表单数据包含在您的电子邮件中。

例如,而不是在你的asp:

sendTo = "MYEMAIL"     'Insert the email address to send to in here

您应该使用以下表单中的电子邮件:

sendTo = Request.Form("Email")     'Insert the email address to send to in here

您可能需要先验证电子邮件地址:

if isEmailValid(Request.Form("Email")) = true then
    '#### Send your email
else
    '#### Email was invalid, give the user an error
    response.write "Invalid email address"
end if

Function isEmailValid(email) 
    Set regEx = New RegExp 
    regEx.Pattern = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$" 
    isEmailValid = regEx.Test(trim(email)) 
End Function 

要确认,request.form集合使用HTML表单的name =“”属性。 即包括textarea的内容:

'Add the email body text
objCdoMessage.TextBody = "The following comment was submitted via the feedback form:" & Request.Form("Comments")