0

试图在 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 表单中包含的任何信息。

通常不使用表格,因此我们将不胜感激地收到任何建议。

谢谢,

4

1 回答 1

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="" 属性。即包括你的文本区域的内容:

'Add the email body text
objCdoMessage.TextBody = "The following comment was submitted via the feedback form:" & Request.Form("Comments")
于 2012-07-29T15:57:53.383 回答